Tag Info

Hot answers tagged


You're on the right track with sed: all you need to do is to transform your list of line numbers to be followed by a p and a newline, and use that as a sed script. For example, if you have a space-separated list: lines="2 3 5 7 11 13" <sourcefile.tsv sed -n "$(echo "$lines" | sed 's/$/p/; s/ /p\n/')" >extractedrecords.tsv Awk is another ...


Assuming linenumbers.txt has one number per line awk 'NR == FNR{a[$0]; next};FNR in a' linenumbers.txt sourcefile.csv > extractedrecords.tsv Might do the job. Or, with bash join -t':' -o2.1,2.2 <(sort linenumbers.txt) <(awk '{print NR":"$0}' \ sourcefile.csv | sort -k1,1 -t':') | sort -k1,1n -t':' | cut -f2- -d':' All the extra jumping ...

Only top voted, non community-wiki answers of a minimum length are eligible