now i have a different file zoo.txt with content
123|zoo
234|natan
456|don
and file rick.txt with contents
123|dog|pie|pep
123|tail|see|newt
456|som|sin|sim
234|pay|rat|cat
i want to look for lines in file zoo.txt column1 that has same corresponding lines in column 1 of file rick.txt . then output all lines in file zoo.txt and column 2,3 of file rick.txt. should look like
123|zoo|dog|pie
123|zoo|tail|see
456|don|som|sin
234|natan|pay|rat
nawk -F'|' 'FNR==NR{f2[$1]=$2 FS $3;next} $NF=$NF FS f2[$1]' OFS='|' rick.txt zoo.txt
ooops, not exactly what's needed......
i am unable to use nawk, i get some error
define 'some error', please. What happens?
Try using 'awk' or 'gawk' instead.
What OS are you under?
Either way, this solution doesn't provide exactly what you're after and I have to run. Other will be able to tweak it for you.
Good luck!
when i use awk i get the output
123|zoo|tail|see
234|natan|pay|rat
456|don|som|sin
it should be
123|zoo|dog|pie
123|zoo|tail|see
234|natan|pay|rat
456|don|som|sin
Try this:
awk -F"|" 'NR==FNR{a[$1]=$2; next}
a[$1]{print $1 FS a[$1] FS $2 FS $3}
' zoo.txt rick.txt
awk 'NR==FNR{a[$1]=$1 FS $2;next}a[$1]{print a[$1] FS $2 FS $3}' FS="|" zoo rick
123|zoo|dog|pie
123|zoo|tail|see
456|don|som|sin
234|natan|pay|rat