<p>Assuming you want to only show the fifth id from the first field, the following Perl script should work:</p>
<pre><code>perl -pe 's/^(.*?)\t//; @F=split(&quot;\\|&quot;, $1); print(@F[4].&quot;\t&quot;)' input.tsv &gt; output.tsv
</code></pre>
<p>Explanation of the Perl code:</p>
<ol>
<li>Loop over the lines in the input file (this is enabled by the command-line option <code>-p</code>)</li>
<li>Remove everything up to the first tab character from the input line, and save the removed part (excluding tab character) into the grouping variable <code>$1</code> [identified by brackets].</li>
<li>Split variable <code>$1</code> at the pipe character, <code>|</code>, saving the split components into the array <code>@F</code></li>
<li>Print the fifth field [0,1,2,3,<strong>4</strong>] from the array <code>@F</code> [without a line break at the end]</li>
<li>Print the remainder of the input line (this is also enabled by the command-line option <code>-p</code>)</li>
</ol>

CC BY-SA 4.0
2020-06-26T13:18:12.407Z
DDX11L1-202 is in the very first line of the excel document 5th character in the pipe.
Amit
CC BY-SA 4.0
2020-06-26T01:37:30.643Z
2020-06-26T22:07:52.900Z
2020-06-26T22:07:52.900Z
gringer
<p>You need the first column's 6th component when split by <code>|</code> and then the remaining columns of the file where <code>\t</code> is the delimiter. Use awk.</p>
<pre><code>awk -F &quot;\t&quot; -vOFS=&quot;\t&quot; 'NR==1 {print} NR&gt;1{split(<span class="math-container">$1,arr,"|"); print arr[6],$</span>2,<span class="math-container">$3,$</span>4,$5}' your_file
</code></pre>

CC BY-SA 4.0
2020-06-26T13:49:52.723Z
2020-06-26T13:49:52.723Z
Ram RS
<p>You could just do this in libreoffice calc using text to columns (data menu)</p>
<p>If you want to use awk (or maybe gawk) you could use capture groups; but rather that mess around with a fairly complex regex I'd probably do it in two stages like below</p>
<pre><code>awk -F&quot;|&quot; '{print <span class="math-container">$5,$</span>0}' OFS=&quot;\t&quot; your_file|\
awk -F&quot;\t&quot; '{print <span class="math-container">$1,substr($</span>0,index(<span class="math-container">$0,$</span>3))}'
</code></pre>
<p>The second awk prints everything except field 2</p>

CC BY-SA 4.0
2020-06-25T11:27:03.153Z
DDX11L1-202 1657|lncRNA| it retains the other columns with pipes.
Amit
CC BY-SA 4.0
2020-06-25T11:18:20.363Z
2020-06-25T11:18:20.363Z
Greg
<p>I have a file like this :
<a href="https://i.sstatic.net/448hu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/448hu.png" alt="enter image description here" /></a></p>
<p>and I want the output as:</p>
<p><a href="https://i.sstatic.net/jNzse.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jNzse.png" alt="enter image description here" /></a></p>
<p>I tried using awk :</p>
<pre><code>awk 'BEGIN { OFS=FS=&quot;\t&quot; } { sub(&quot;\\..*&quot;, &quot;&quot;, $1); print }'
</code></pre>
<p>and it prints the first id ENST.
But when I change it to:</p>
<pre><code>awk 'BEGIN { OFS=FS=&quot;\t&quot; } { sub(&quot;\\..*&quot;, &quot;&quot;, $5); print }'
</code></pre>
<p>it doesnt work.</p>
<p>What is wrong that I am doing here. Kindly help.</p>

CC BY-SA 4.0
2020-06-26T08:07:33.513Z
could you please provide a text-format toy example (or first few lines) of your input file? that would help to quickly see an application of your tests with awk.
aechchiki
CC BY-SA 4.0
2020-06-26T13:28:59.227Z
done.KIndly see
Amit
CC BY-SA 4.0
2020-06-26T23:27:40.583Z
thanks, although i meant more in an easily copy-pastable text format (not a screenshot) in a code snippet for example, same you used to write in your awk lines
aechchiki
<awk>
awk field separtor
# awk field separtor

(Asked by: username_0 on 2020-06-25)

I have a file like this :

and I want the output as:

I tried using awk :
awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "", $1); print }'

and it prints the first id ENST.
But when I change it to:
awk 'BEGIN { OFS=FS="\t" } { sub("\\..*", "", $5); print }'

it doesnt work.
What is wrong that I am doing here. Kindly help.

**Tags:** awk
> **Comments:**
> **username_1**: could you please provide a text-format toy example (or first few lines) of your input file? that would help to quickly see an application of your tests with awk.  
> **username_0**: done.KIndly see  
> **username_1**: thanks, although i meant more in an easily copy-pastable text format (not a screenshot) in a code snippet for example, same you used to write in your awk lines  

---

## 3 answers

### Answer by username_2 on 2020-06-26. Score: 2

Assuming you want to only show the fifth id from the first field, the following Perl script should work:
perl -pe 's/^(.*?)\t//; @F=split("\\|", $1); print(@F[4]."\t")' input.tsv > output.tsv

Explanation of the Perl code:

Loop over the lines in the input file (this is enabled by the command-line option -p)
Remove everything up to the first tab character from the input line, and save the removed part (excluding tab character) into the grouping variable $1 [identified by brackets].
Split variable $1 at the pipe character, |, saving the split components into the array @F
Print the fifth field [0,1,2,3,4] from the array @F [without a line break at the end]
Print the remainder of the input line (this is also enabled by the command-line option -p)

> **Comments:**
> **username_0**: DDX11L1-202 is in the very first line of the excel document 5th character in the pipe.  

---

### Answer by username_3 on 2020-06-26. Score: 1

You need the first column's 6th component when split by | and then the remaining columns of the file where \t is the delimiter. Use awk.
awk -F "\t" -vOFS="\t" 'NR==1 {print} NR>1{split($1,arr,"|"); print arr[6],$2,$3,$4,$5}' your_file


---

### Answer by username_4 on 2020-06-25. Score: 0

You could just do this in libreoffice calc using text to columns (data menu)
If you want to use awk (or maybe gawk) you could use capture groups; but rather that mess around with a fairly complex regex I'd probably do it in two stages like below
awk -F"|" '{print $5,$0}' OFS="\t" your_file|\
awk -F"\t" '{print $1,substr($0,index($0,$3))}'

The second awk prints everything except field 2

> **Comments:**
> **username_0**: DDX11L1-202 1657|lncRNA| it retains the other columns with pipes.  

---

