InsideDarkWeb.com

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

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?

Ask Ubuntu Asked by deep771992 on November 14, 2021

2 Answers

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!

Related Questions

Installing a different Nvidia driver

1  Asked on December 16, 2020 by yehuda

     

Restrict telnet access on Ubuntu 16.04.7 LTS using username/password

0  Asked on December 15, 2020 by flying-dutch

   

Can’t increase the number of recent documents in gedit

1  Asked on December 15, 2020 by os-meservo

     

How to set up Dolphin as default file manager?

5  Asked on December 14, 2020 by cloxy

 

Most Efficient Way To Play HEVC / x265

2  Asked on December 14, 2020 by markus-gratis

   

-bash: syntax error near unexpected token `(‘

0  Asked on December 14, 2020 by p4ck4dzdzvjsjoukqrrl

 

Battery charge suddenly drops from 100% to 0%

0  Asked on December 14, 2020 by syndo-rik

     

How to completely disable apparmor for Firefox? (sanitized_helper etc…)

0  Asked on December 14, 2020 by chromium_snap23123123

   

NVIDIA GeForce 7300 GT legacy driver on 20.04

2  Asked on December 14, 2020 by tadejp

         

How do I pop-up “select audio device” from command line?

1  Asked on December 13, 2020 by vitor-abella

     

Are there any Lubuntu server version?

2  Asked on December 13, 2020 by emoji

   

Can’t connect to local MySQL server through socket problem

0  Asked on December 13, 2020 by silver-dangeros

       

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.