I have some query relating to some files.

Inputs :

List=”R1  7n  3n”  “R2  8n  1n”  “R3  1n  2n”  “R4  2n  3n”  “R5  3n  4n”

In output I want new list should start with the string having 1n information. New list:

“R2 8n 1n” “R3 1n 2n” “R4 2n 3n” “R5 3n 4n”

Please confirm can I do it with the help of Shell commands operations.


Please explain what is quotes? Is it usual "? If not - just substitute it in scripts.

If you can modify file1 to "[^"]1n.* it would be easy use grep

grep -of file1 file2 > file3

If not you are free to use sed

grep -o "$(sed -E 's/(.)(.*)(.)/\1[^\3]*\2.*/' file1)" file2 > file3

or even read

grep -o "$(read -r r <file;q=${r%${r#?}};printf "$q[^$q]*${r//["]/}.*")" file2 > file3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.