I have been able to extract certain lines from a large tab-separated text file and write them to another file:
sed -n 100,200p file.tsv >> output.txt
However, I am actually trying to grab the 8th tab-separated value from each line and write them to a file comma separated, but I cannot find the right syntax to use for the pattern matching, despite reading dozens of online articles.
For each time I have basically been trying to match
$2 in /([^\t]*\t){7}([0-9]*).*/
with no luck.
The lines within the text file file.tsv resemble:
01 name1 title1 summary1 desc1 image1 url1 120019 time1
02 name2 title2 summary2 desc2 image2 url2 576689 time2
Please can anyone help me with this query?
Here it is using GNU sed and extended expressions:
Here it is using POSIX only:
I do agree with Alf that
awkwould be a better fit for this.Here is the
awksolution with line limits: