I want to move lines from a text file into another text file. Those lines contain a word beginning with an underscore. This word is located on the sixth field of the lines; fields are separated with forward slashes. For example, move lines containing
_Nokia on the sixth field, in the sample input file, below.
Apple/One-plus/Samsung/Mi/Sony/_Nokia/ Apple/One-plus/Samsung/Mi/Lenovo/_Nokia/ Apple/One-plus/Samsung/Mi/HTC/OPPO/
I have tried to move corresponding lines, with a regular expression, using
grep, but it does not work.
$ grep -F 'Apple/One-plus/Samsung/Mi/^[a-zA-Z]([\w -]*[a-zA-Z])?$/_Nokia/' match.txt >file1.txt $ grep -F -v "Apple/One-plus/Samsung/Mi/^[a-zA-Z]([\w -]*[a-zA-Z])?$/_Nokia/" match.txt \ > match.txt.tmp && mv match.txt.tmp match
$ cat file1.txt Apple/One-plus/Samsung/Mi/Sony/_Nokia/ Apple/One-plus/Samsung/Mi/Lenovo/_Nokia/ $ cat match Apple/One-plus/Samsung/Mi/HTC/OPPO/
How to move a line from a file to the other file on the basis of pattern matching?