![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|