Monday, June 5, 2017

command line - using sed to loop through records in a file and use grep on all records

I am trying to find strings from one file in another file and I need to have the search string printed once, and the lines for matches following.



The strings I want to find matches for are in a file with 2 lines per record, no empty lines etc. Line 1 contains the name, line 2 the string I need to find in the second file. sed -n '1~2p' will print all the names, but I will need to print only the first name, pass the value of the second line to grep, execute the grep command, then print the second record's name (line 3), pass line 4 to grep and so on.
An alternative would be to use a while or until loop with a counter incremented by 2, but then I don't know how to pass the value of counter to sed.

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...