Ignore identical lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignore identical lines
# 1  
Old 11-18-2008
Ignore identical lines

Hello Experts,

I have two files called "old" and "new". My old file contains 10 lines and my new file contains 10 + "n" lines.

The first field in both these files contain ID. I sort these two files on ID. I am interested in only the lines that are in the new file and not in old.

I tried the below but was not successful

awk -F"\t" '{a[$] = $0} END { for (x in a) { print a[x] } }' maout > nodup

I have attached a file which gives an example of how my input files look like and the output i expect

Any suggestions would be appreciated.

Many Thanks in advance.
# 2  
Old 11-18-2008
With awk:

Code:
awk 'NR==FNR{a[$0];next}!($0 in a)' old new

With grep:

Code:
grep -v -f old new

# 3  
Old 11-19-2008
Hello Franklin,

Many thanks for your reply.

I tried both awk and grep commands but get syntax errors.

For the grep command the error is

>grep -v -f old new
grep: illegal option --f

For the awk command this is what i get

>awk 'NR==FNR{a[$0];next}!($0 in a)' old new
awk: syntax error near line 1
awk: bailing out near line

could you let me know where i am going wrong please.

Thanks again
# 4  
Old 11-19-2008
diff can help you...

diff old new
6a7,9
> cc_03 1 uio yui
> cc_04 1 qwe abc
> cc_04 2 abc xyz
# 5  
Old 11-19-2008
Quote:
Originally Posted by forumthreads
For the grep command the error is

>grep -v -f old new
grep: illegal option --f
Have you adjust the line with the your own filenames?

Quote:
Originally Posted by forumthreads
For the awk command this is what i get

>awk 'NR==FNR{a[$0];next}!($0 in a)' old new
awk: syntax error near line 1
awk: bailing out near line
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk - If field value of consecutive records are the identical print portion of lines

I have some data that looks like this: PXD= ZW< 1,6 QR> QRJ== 1,2(5) QR> QRJ== 4,1(2) QR> QRJ== 4,2 QRB= QRB 4,2 QWM QWM 6,2 R<C ZW< 11,2 R<H= R<J= 6,1 R>H XZJ= 1,2(2) R>H XZJ= 2,6(2) R>H XZJ= 4,1(2) R>H XZJ= 6,2 RDP RDP 1,2 What I would like to do is if fields $1 and $2 are... (5 Replies)
Discussion started by: jvoot
5 Replies

2. UNIX for Beginners Questions & Answers

How to delete identical lines while leaving one undeleted?

Hi, I have a file as follows. file1 Hello Hi His Hi Hi Hungry hi so I want to delete identical lines while leaving one of them undeleted. So desired output will be Hello Hi (2 Replies)
Discussion started by: beginner_99
2 Replies

3. Shell Programming and Scripting

Combine identical lines and average the one variable field

I have the following file 299899 chrX_299716_300082 196 78.2903 299991 chrX_299982_300000 18.2538 Tajd:0.745591 FayWu:-0.245701 T2:1.45 299899 chrX_299716_300082 196 78.2903 299991 chrX_299982_300000 18.2538 Tajd:0.745591 FayWu:-0.245701 T2:0.283 311027 chrX_310892_311162 300 91.6452... (2 Replies)
Discussion started by: jfern
2 Replies

4. Shell Programming and Scripting

sed print all lines between second and third identical lines

I am trying to extract a table of data (mysql query output) from a log file. I need to print everything below the header and not past the end of the table. I have spent many hours searching with little progress. I am matching the regexp +-\{99\} with no problem. I just can't figure out how to print... (5 Replies)
Discussion started by: godfreydanials
5 Replies

5. Shell Programming and Scripting

Scan a file in realtime and execute certain commands on encountering 5 consecutive identical lines

Mysql log has something like below: I need a bash shell script that will do the following: 1) The script will scan the mysql.log file constantly in real time (something like tail -F mysql.log) 2) If it encounters 5 consecutive identical lines then it would invoke some commands (say... (4 Replies)
Discussion started by: proactiveaditya
4 Replies

6. UNIX for Dummies Questions & Answers

more than 10 identical lines

I have a file that looks like this 10 user1s, 5 user2s and 10 users3. 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.2 user2 10.10.1.2 user2 10.10.1.2 user2... (7 Replies)
Discussion started by: lawsongeek
7 Replies

7. Shell Programming and Scripting

expect - How to ignore empty lines?

Hi all, I'm looking for a way to generate an error when a command does not print an expected message. For example : test.sh : echo hi!test.exp : exp_internal 1 spawn ./test.sh expect { "hi!" {puts "bingo!"} "*" {puts "error!" ; exit 1} } I expected test.exp to match the string... (2 Replies)
Discussion started by: whbos
2 Replies

8. Shell Programming and Scripting

replace 2 identical strings on different lines

I am looking to replace two or more strings on different lines using sed, but not with the same variable. IE # cat xxx.file <abc> abc def ghi abc def ghi abc def ghi currently I can only change each line with the same pattern: # sed -e '/<abc>/!s/abc\(.*\)/jkl mno/' xxx.file abc jkl mno... (3 Replies)
Discussion started by: prkfriryce
3 Replies

9. Shell Programming and Scripting

How can I ignore only the lines which have # at the begining?

From the below file I want to grep only the lines except the comment sections. But grep -v "#" is eliminating the last line because it has one # in between. Any idea how can I ignore only the lines which have # at the begining (I mean comment lines) ? Thanks a lot to all in advance C Saha (1 Reply)
Discussion started by: csaha
1 Replies

10. Shell Programming and Scripting

Ignore Lines Begining With #

Is there a standard way to make a shell script read a file, or list, and skip each line that contains # at the begining, or ignores the content starting after a # in line? I'm looking to mimic the way commenting in a shell script normally works. This way I can comment my text files and lists my... (4 Replies)
Discussion started by: sysera
4 Replies
Login or Register to Ask a Question