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
Using grep to compare files and extract the difference to another output file spartan22 UNIX for Dummies Questions & Answers 6 02-23-2009 04:51 PM
Compare two arrays in sh or compare two fields rijeshpp Shell Programming and Scripting 0 10-31-2007 02:47 AM
I need to extract last column of a file and compare the values vukkusila Shell Programming and Scripting 4 08-04-2007 12:21 PM
compare two tar.bz2 JCR Shell Programming and Scripting 2 07-30-2007 12:16 PM
How to compare it ?? sabercats Shell Programming and Scripting 4 02-16-2006 06:07 PM

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 05-15-2009
ford2020 ford2020 is offline
Registered User
  
 

Join Date: May 2009
Posts: 18
Compare and extract

Compare two files, search for data from position 1-6 if both matches then i need to extract those records only from file A

cat File A
A37985LUNGIUF7845049530113
F41604CHACAMA286000004371

cat File B
C26344
F41604

o/p
F41604CHACAMA286000004371
  #2 (permalink)  
Old 05-15-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk 'FNR==NR {a[substr($0,1,6)]++;next} substr($0,1,6) in a' fileB fileA

  #3 (permalink)  
Old 05-15-2009
ford2020 ford2020 is offline
Registered User
  
 

Join Date: May 2009
Posts: 18
I am getting error
-bash: nawk: command not found
  #4 (permalink)  
Old 05-15-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
try awk or gawk (obviously)
  #5 (permalink)  
Old 05-15-2009
ford2020 ford2020 is offline
Registered User
  
 

Join Date: May 2009
Posts: 18
i tried using awk
awk: cmd. line:1: FNR=NR {a[substr($0,1,6)]++;next} substr($0,1,6) in a}
awk: cmd. line:1: ^ parse r
  #6 (permalink)  
Old 05-15-2009
ford2020 ford2020 is offline
Registered User
  
 

Join Date: May 2009
Posts: 18
I am not able to do by gawk also....
gawk: cmd. line:1: FNR=NR {a[substr($0,1,6)]++;next} substr($0,1,6) in a}
gawk: cmd. line:1: ^ parse
  #7 (permalink)  
Old 05-15-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
I'm not sure if you copy/pasted it correctly - check the posting.
Closed Thread

Bookmarks

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 02:19 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