bedtools unable to open file despite being tab-delimited I got the following error when attempting to intersect two files. The file below is supposed to be the -a file.

Error: Unable to open file compare_me_to.txt. Exiting.


When I attempted to make it tab-delimited through Ubuntu (see code below)

perl -p -i -e 's/ /\t/g' compare_me_to.txt


I got the following error:

Can't open compare_me_to: Permission denied.


Additionally, the ownership of the folder the files are in is of my username.
I can't tell if this is a bedtools problem or a Ubuntu problem or something else.
I suspect the reason is the "-i". The following will work,

perl -pe 's/  */\t/g' compare_me_to.txt &gt; compare_me_to.txt2


-i will want to write onto the file and create a backup. I suspect you'll have spotted chmod +w compare_me_to.txt.

Just make sure that a double space is inserted before the * character, otherwise it will go wrong. Copying and pasting will avoid this.



This is a clearer solution because it avoids missing a space character,

perl -e 's/[ ][ ]*/\t/g' compare_me_to.txt &gt; compare_me_to.txt2


and the solution you used .. (I did on OS X), what I'd recommend is,

perl -p -e 's/[ ][ ]*/\t/g' compare_me_to.txt # to see if it works by printing on screen without altering the file

perl -i -e 's/[ ][ ]*/\t/g' compare_me_to.txt


The  -i flag will alter the original file and store a backup without requiring renaming the file.

What's it doing?
The regex [ ][ ]* structure is saying look a space and if one or more spaces occur adjacent to each other replace everything with a single tab. [ ]* means a "space" that is present or absent and if present it can be present an infinite number of times. If the [ ]* is by itself the command risks saying replace '' (zip) or 'space' with a tab, so tabs can appear at every '' (zilch), so tabs can appear everywhere. The "*" symbol in regex work differently to the "*" wildcard character in shell.