![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help Required: Command to find IP address and command executed of a user | loggedout | Security | 2 | 08-06-2008 05:12 PM |
| how to? launch command with string of command line options | TinCanFury | Shell Programming and Scripting | 5 | 04-28-2008 03:06 PM |
| inconsistent ls command display at the command prompt & running as a cron job | rajranibl | Linux | 5 | 07-30-2007 05:26 AM |
| How to use more than one MPE command STREAM with Unix command in a single shell? | bosskr | HP-UX | 1 | 10-16-2006 01:16 PM |
| How to use more than one MPE command STREAM with Unix command in a single shell? | bosskr | Shell Programming and Scripting | 0 | 09-19-2006 06:44 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk command
I am making an awk command file to run on my UNIX box. I have 2 files:
file 1 file 2 1111 Jones/Ron ,P,2222 2222 Smith/John ,P,7788 3333 Smith/Jim ,P,9999 4444 Carter/Jane ,P,4444 I want to compare these 2 files. If there is anybody in file 2 that has the 3rd field match up with the field in file 1, I want to make a new file with their information. In this example, I would have a new file (file 3) that would contain: Jones/Ron ,P,2222 Carter/Jane ,P,4444 I want to be able to do this in the command file format: example awk -f (name of my awk command file) File 1 > File 3 How do I do this? Thanks, Nick |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
awk -F"," 'BEGIN{ while(getline < "1" ) { arr[$0]=i++ } } { split($0, now, ","); if ( now[3] in arr ) { print } }' 2
|
|
#3
|
|||
|
|||
|
awk
And how would I run this in the command file format?
thanks |
|
#4
|
|||
|
|||
|
Sorry your question is not clear.
Are you looking for something like, to use the command in a script.awk file... something like that.. then just include the command posted into a script.awk file. |
|
#5
|
|||
|
|||
|
awk
Please forgive me for asking so many questions. I am just learning awk and I have a longgggg way to go.
Ok, so I put your script into an awk file called AWK1. I want to run it like this: awk -f AWK1 file 2 > file 3 I want the output to go to file 3. I need file 2 to reference file 1. This would be done in your awk script. I don't see the file references in your awk script. I put examples of file 1 and file 2 in my original post. |
|
#6
|
|||
|
|||
|
file 1 ==> 1
file 2 ==> 2 redirect the output of the awk command to file3 awk command > file 3 |
|
#7
|
||||
|
||||
|
nawk -F',' -f nickg.awk file1 file2
nickg.awk: Code:
FNR==NR {arr[$1]; next }
$3 in arr
|
||||
| Google The UNIX and Linux Forums |