The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk, ignore first x number of lines. trey85stang Shell Programming and Scripting 8 05-21-2008 05:44 AM
replace 2 identical strings on different lines prkfriryce Shell Programming and Scripting 3 06-15-2007 12:18 PM
How can I ignore only the lines which have # at the begining? csaha Shell Programming and Scripting 1 01-30-2006 03:35 AM
Ignore Lines Begining With # sysera Shell Programming and Scripting 4 08-23-2005 10:04 AM
Make sed ignore lines Scarlos Shell Programming and Scripting 2 07-21-2005 11:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-18-2008
forumthreads forumthreads is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 20
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.
Attached Files
File Type: txt Input & Output.txt (896 Bytes, 20 views)
  #2 (permalink)  
Old 11-18-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345
With awk:


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

With grep:


Code:
grep -v -f old new

  #3 (permalink)  
Old 11-19-2008
forumthreads forumthreads is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 20
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 (permalink)  
Old 11-19-2008
dddkiran dddkiran is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 25
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 (permalink)  
Old 11-19-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,345
Quote:
Originally Posted by forumthreads View Post
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 View Post
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
Closed Thread

Bookmarks

Tags
nawk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0