text: user7236: 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.
  
  user650: 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
  
  
  user73: 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)
  
  
original_text: 7236: <p>I have a file like this :
  <a href="https://i.stack.imgur.com/448hu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/448hu.png" alt="enter image description here" /></a></p>
  <p>and I want the output as:</p>
  <p><a href="https://i.stack.imgur.com/jNzse.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/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>
   650: <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>
   73: <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>
  