![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| combining fields in two text fields | shocker | Shell Programming and Scripting | 3 | 01-16-2008 08:27 AM |
| joining the data | vakharia Mahesh | UNIX Desktop for Dummies Questions & Answers | 0 | 03-15-2007 08:49 AM |
| Help with joining two files | rjlohman | Shell Programming and Scripting | 3 | 09-27-2006 08:55 AM |
| joining files | Manu | UNIX for Dummies Questions & Answers | 2 | 04-25-2005 09:24 AM |
| joining 2 files | webtekie | UNIX for Dummies Questions & Answers | 1 | 10-21-2003 07:51 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
awk
Hi,
Awk should be ok for you. a: Code:
20071121|12|Mohit|DAV 20071222|13|Dev|MRSD 20071011|14|Rajan|ST 20071011|15|Lali|OTH Code:
12|KKP|Pun|Mohit 14|FDK|Pas|Abhi 15|SAD|Hp|Lali Code:
12|Mohit|20071121|DAV|KKP|Pun 15|Lali|20071011|OTH|SAD|Hp Code:
nawk 'BEGIN{FS="|"}
NR==FNR {
temp1=sprintf("%s|%s",$2,$3)
t[temp1]=sprintf("%s|%s|%s|%s",$2,$3,$1,$4)}
NR!=FNR {
temp2=sprintf("%s|%s",$1,$4)
if (t[temp2])
printf("%s|%s|%s\n",t[temp2],$2,$3)
}
' a b
|
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
how to use "where" condition?
if i want to get the row in which a particular condition is req,
than how can i do it? Like in the above given file if i want to extract only the row where second column =12 in the first file. Please help me as soon as possible. Thanks |
|
#10
|
||||
|
||||
|
Code:
column_f1=2
value=12
awk 'FNR == NR && $'${column_f1}' == '${value}' { n=FR;print;break }
/'${value}'/ FNR == n {print}' FS=\| f1 f2
20071121|12|Mohit|DAV
|
|
#11
|
|||
|
|||
|
Could you please explain the code?
Hi,
I checked your code and it works great, but I can understand it very well... nawk 'BEGIN{FS="|"} NR==FNR { <<< what does this section do? I thought it meant when the combination of fields is found then do whatever.... but the print is in the next section temp1=sprintf("%s|%s",$2,$3) t[temp1]=sprintf("%s|%s|%s|%s",$2,$3,$1,$4)} NR!=FNR { temp2=sprintf("%s|%s",$1,$4) if (t[temp2]) printf("%s|%s|%s\n",t[temp2],$2,$3) } ' a b I'm changing some values to try to understand it better but I'm still confused... Thanks, Quote:
|
|||
| Google The UNIX and Linux Forums |