I wish to print lines that are in one file but not in another file. However, neither files are sorted, and I need to retain the original order in both files.
contents of file1: string2 string1 string3 contents of file2: string3 string1 Output: string2
Is there a simple script that I can accomplish this in?
You can add the -l option to print just the file name; but this still prints the names of any file which contains any line which does not contain the pattern.
To get third column in tab delimited file, you can simply call it as cut -f3 <file> . Different delimiter can be passed via -d parameter, e.g.: cut -f3 -d: . You can even get multiple columns, or characters at fixed positions on the line.
To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.
fgrep -x -f file2 -v file1
-x match whole line
-f FILE takes patterns from FILE
-v inverts results (show non-matching)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With