TransWikia.com

Extract out lines with "s__" into a new file together with first two lines of the file

Ask Ubuntu Asked by deep771992 on November 14, 2021

I have a file from where I want to extract the first two lines (starting with "ID" and "#SampleID") along with all the lines that contain "s__" in that line. And, want to put them in a new file. Can anyone please tell me how can I do that?

2 Answers

grep -m2 "" your.file > test.txt; grep "s__" your.file >> test.txt

Answered by WU-TANG on November 14, 2021

awk 'NR<3 || /s__/' yourfile > newfile

or

sed -n -e '1,2p' -e '/s__/p' yourfile > newfile

Answered by steeldriver on November 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP