<p>I suspect the reason is the "-i". The following will work,</p>

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

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

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

<hr>

<p>This is a clearer solution because it avoids missing a space character,</p>

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

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

<pre><code>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
</code></pre>

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

<p><strong>What's it doing?</strong>
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.</p>

CC BY-SA 4.0
2019-03-11T06:51:11.977Z
The following error appears: `Can't open compare_me_to.txt: Permission denied.`
DangIt
CC BY-SA 4.0
2019-03-11T07:20:37.190Z
I was able to give myself permission (https://askubuntu.com/questions/466605/cannot-open-output-file-permission-denied), but the file still can't be opened when intersecting. I ran the line of code you wrote; when I opened the resulting file, every character was separated by a tab.
DangIt
CC BY-SA 4.0
2019-03-11T12:39:24.943Z
Oh I know, you put a single space into the term ... its a double space followed by a *. so its ... 's/  */\t/g' ... if you only put a single space into the first / */ then it will result in tabs going everywhere. I can explain later.
M__
CC BY-SA 4.0
2019-03-11T12:42:13.133Z
chmod 700 file_name is another way in, I'm surprised chmod +w file_name didn't work if you were the file owner. I assumed you knew about chown and chmod
M__
CC BY-SA 4.0
2019-03-07T03:00:30.303Z
2019-03-11T17:39:16.347Z
2019-03-11T17:39:16.347Z
M__
<p>I got the following error when attempting to intersect two files. The file below is supposed to be the -a file.</p>

<pre><code>Error: Unable to open file compare_me_to.txt. Exiting.
</code></pre>

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

<pre><code>perl -p -i -e 's/ /\t/g' compare_me_to.txt
</code></pre>

<p>I got the following error:</p>

<pre><code>Can't open compare_me_to: Permission denied.
</code></pre>

<p>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.</p>

CC BY-SA 4.0
2019-03-06T21:18:44.657Z
Just a quick check since you said you have ownership of the file... The file isn't open anywhere else (like in another shell or on desktop) when you try to convert right?
d_kennetz
<bedtools>
bedtools unable to open file despite being tab-delimited
# bedtools unable to open file despite being tab-delimited

(Asked by: username_0 on 2019-03-06)

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.

**Tags:** bedtools
> **Comments:**
> **username_1**: Just a quick check since you said you have ownership of the file... The file isn't open anywhere else (like in another shell or on desktop) when you try to convert right?  

---

## 1 answers

### Answer by username_2 on 2019-03-07. Score: 1

I suspect the reason is the "-i". The following will work,
perl -pe 's/  */\t/g' compare_me_to.txt > 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 > 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.

> **Comments:**
> **username_0**: The following error appears: `Can't open compare_me_to.txt: Permission denied.`  
> **username_0**: I was able to give myself permission (https://askubuntu.com/questions/466605/cannot-open-output-file-permission-denied), but the file still can't be opened when intersecting. I ran the line of code you wrote; when I opened the resulting file, every character was separated by a tab.  
> **username_2**: Oh I know, you put a single space into the term ... its a double space followed by a *. so its ... 's/  */\t/g' ... if you only put a single space into the first / */ then it will result in tabs going everywhere. I can explain later.  
> **username_2**: chmod 700 file_name is another way in, I'm surprised chmod +w file_name didn't work if you were the file owner. I assumed you knew about chown and chmod  

---

