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
Please explain this appsdba.nitin UNIX for Dummies Questions & Answers 2 09-24-2008 12:54 PM
Please can any one explain this ${0##/} gadege Shell Programming and Scripting 2 04-01-2008 04:26 PM
Can anyone explain plz r_W213 UNIX for Advanced & Expert Users 3 03-27-2007 05:52 AM
if [ $? -eq 0 ] .. can someone explain this? ranjita.c Shell Programming and Scripting 5 10-03-2006 08:50 PM
Explain awk hitmansilentass Shell Programming and Scripting 4 09-27-2006 03:14 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-27-2009
maxim42 maxim42 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 15
can any one explain this example

hi all i have an example i want one help me to understand cause i tried to test it but almost fail and i don't know how can i solve this problem " the main idea to read from two files and replace something from one to another " but i don't understand why it fail all time



Code:
$ cat main.txt
512|1241503759|ax|90
234|1241503760|ay|10
122|1241503823|az|90
123|1241503947|at|80



Code:
$ cat id.txt
122|US
123|IN
125|NZ
234|HK
512|ZM
600|KR



Code:
$ awk '
    BEGIN {FS=OFS="|"}
    FNR==NR{a[$1]=$2;next}
    $1 in a{print a[$1],$2,$3,$4}
' id.txt main.txt


Code:
Output:
ZM|1241503759|ax|90
HK|1241503760|ay|10
US|1241503823|az|90
IN|1241503947|at|80

i tried this

Code:
awk 'BEGIN { FS=OFS="|" } FNR==NR{ a[$1]=$2;next } $1 in a { print a[$1] }' id.txt  main.txt
awk: syntax error near line 1
awk: bailing out near line 1

when i remove " $1 in a "


Code:
awk 'BEGIN { FS=OFS="|" } FNR==NR{ a[$1]=$2;next } { print a[$1] }' id.txt  main.txt

it prints spaces

i want one help me to explain this thing plz
  #2 (permalink)  
Old 05-27-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,334
Use nawk, gawk or /usr/xpg4/bin/awk on Solaris.

Regards
  #3 (permalink)  
Old 05-27-2009
maxim42 maxim42 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 15
ok thanks but i want to know why it is work with this path /usr/xpg4/bin/awk
and doesn't work with /usr/bin/awk
  #4 (permalink)  
Old 05-27-2009
kodak kodak is offline
Registered User
  
 

Join Date: Jun 2003
Posts: 51
They are different versions of awk.
  #5 (permalink)  
Old 05-27-2009
maxim42 maxim42 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 15
ok thanks dude
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 05:52 PM.


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