Filter files by exact line anywhere in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter files by exact line anywhere in file
# 1  
Old 09-05-2011
Filter files by exact line anywhere in file

I have two files. L1 and L2. (each file, has one string per line without any spaces)

I would like to get those lines in L1 that are not present anywhere in L2.

No substring match, just exact line by line match but it can be anywhere in the file. (line 5 in L1 may be present in line 22 of L2, and so on)

Any script to help.

Ex.

L1:
Code:
a123
b123
c123

L2:
Code:
x123
a123
y123
z222
c123

So my output should be
L3:
Code:
b123


Last edited by radoulov; 09-05-2011 at 04:57 PM.. Reason: Code tags.
# 2  
Old 09-05-2011
Take your pick:
PHP Code:
fgrep --f L2 L1 L3
fgrep 
--f L2 L1 L3 
# 3  
Old 09-05-2011
Quote:
Originally Posted by nick2011
No substring match, just exact line by line match
Quote:
Originally Posted by apmcd47
Take your pick:
PHP Code:
fgrep --f L2 L1 L3
fgrep 
--f L2 L1 L3 
Your suggestions aren't quite correct. You need to use -x to ensure that substrings do not match, only entire lines.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add line in exact place

I have one big XML file which contains information about 100 jobs,"JOB JOBISN=" indicates that is a job so where ever tag starts with "JOB JOBISN=" then i need to add below highlighted line between "<INCOND NAME" and "<OUTCOND NAME" for all jobs.like this i want to add below highlighted line for... (7 Replies)
Discussion started by: katakamvivek
7 Replies

2. Shell Programming and Scripting

echo exact xml tag from an exact file

Im stumped on this one. Id like to echo into a .txt file all names for an xml feed in a huge folder. Can that be done?? Id need to echo <name>This name</name> in client.xml files. $path="/mnt/windows/path" echo 'recording names' cd "$path" for names in $path than Im stuck on... (2 Replies)
Discussion started by: graphicsman
2 Replies

3. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

4. UNIX for Advanced & Expert Users

Delete the exact match line from file

Hello All, I have following line and text file line =08 * * 3 /data/reports/bin/xyz.ksh -o customreports.com -f abc.sql -m xyz.com -c -g file:- abc.crontab 08 * * 3 /data/reports/bin/xyz.ksh -o customreports.com -f abc.sql -m xyz.com -c -g 06 * * 3 /data/reports/bin/xyz.ksh -o... (3 Replies)
Discussion started by: anyera
3 Replies

5. Shell Programming and Scripting

[ask]filter with line number in file

dear all about my last question in fileA.txt (all list line i want to find in fileB.txt) is content of line number fileA.txt 23 34 35 55 59 and fileB.txt is content like 24:asd|ekkk|001|001 123:bca|egsd|210|002 1231:cas|egds|322|231 ... in fileB.txt they have line number like... (5 Replies)
Discussion started by: zvtral
5 Replies

6. Shell Programming and Scripting

Finding the line with the exact same number

Hello All, What i am doing is , i tail a file from certain chatacter and then cat -n to get the line numbers.I search for a particular string and gets it line number. What i am interested in is the next line immediately after the pattern i search. But grep gives me result for all line... (5 Replies)
Discussion started by: kailash19
5 Replies

7. Shell Programming and Scripting

How to filter only comments while reading a file including line break characters.

How do I filter only comments and still keep Line breaks at the end of the line!? This is one of the common tasks we all do,, How can we do this in a right way..!? I try to ignore empty lines and commented lines using following approach. test.sh # \040 --> SPACE character octal... (17 Replies)
Discussion started by: kchinnam
17 Replies

8. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies

9. UNIX for Dummies Questions & Answers

how do I filter for a specific line in a file?

It seems like it should be very simple to have a command like grep return a specific line from a file but I can't find anything in the man pages to make grep search by line. I've looked in cat as well. Anyone know how to return a single line from a file? (5 Replies)
Discussion started by: gelitini
5 Replies

10. Shell Programming and Scripting

accessing o an exact line in a file

I want to access exact line in a file (sh script) for example I have a variable input and I want to access input.th line in file. for example line 5 or 7. (2 Replies)
Discussion started by: walnut
2 Replies
Login or Register to Ask a Question