Nawk 2 files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Nawk 2 files
# 1  
Old 05-01-2013
Nawk 2 files

file 1
Code:
abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31|9.516666667
fsdasdf|ferg|12|04|25|21|21|A1|13|02|26|20|31|20.51666667
dfsfsad|gerg|12|04|25|21|21|A1|13|02|25|25|31|4.166666667
wqeqwee|wewe|13|02|01|23|52|A1|13|05|01|09|31|9.516666667

file 2
Code:
abcedef|fsdsa|3000
fsdasdf|dasfa|3200
asasfff|greww|34
dfsfsad|bfsdf|5422
dsddfdd|sweet|7653

I want to join file2 to file 1 : expected result
Code:
abcedef|wert|13|03|10|04|23|A1|13|05|01|09|31|9.516666667|fsdsa|3000
fsdasdf|ferg|12|04|25|21|21|A1|13|02|26|20|31|20.51666667|dasfa|3200
dfsfsad|gerg|12|04|25|21|21|A1|13|02|25|25|31|4.166666667|bfsdf|5422
wqeqwee|wewe|13|02|01|23|52|A1|13|05|01|09|31|9.516666667||

---------- Post updated at 03:49 AM ---------- Previous update was at 03:48 AM ----------

i did this

Code:
nawk -F'|' -v OFS="|" 'FNR==NR{bdl[$1]=$2;next}{print $0,bdl[$1]}' file2 file1 | sort +3 > ouput

# 2  
Old 05-01-2013
Is your problem solved?
# 3  
Old 05-01-2013
not yet,


i tried this
Code:
nawk 'FNR==NR { a[$1]=$2; next } $1 in a { print $1, a[$1], $2, $3 }' file2.dat file1.dat

and also end up with blank result

pls help,
# 4  
Old 05-01-2013
Code:
nawk -F'|' -v OFS="|" 'FNR==NR{bdl[$1]=$2 FS $3;next} {print $0, bdl[$1]}' file2 file1

# 5  
Old 05-01-2013
You miss field 3 from file2
Code:
nawk -F'|' -v OFS="|" '
FNR==NR{bdl[$1]=$2 OFS $3;next}
{print $0,bdl[$1]}' file2 file1

In your 2nd sample, nawk wants brackets: ($1 in a)
# 6  
Old 05-01-2013
tks mr murphy

---------- Post updated at 06:15 AM ---------- Previous update was at 06:14 AM ----------

i have file 1
Code:
aa,20120626
bb,45C

i want to remove all rows when $2 is not ended up with 'C'

expected output

Code:
bb,45C

---------- Post updated at 06:32 AM ---------- Previous update was at 06:15 AM ----------

i run this

Code:
sed -i -nl -e '/\<C\>/ {p;} ' file1

but the result : sed illegal option -i
# 7  
Old 05-01-2013
Ditch sed and "nawk out" this file too Smilie
Set FS="," and test if $2 ends in "C$"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. Shell Programming and Scripting

Merging two tab separated files via nawk

I searched a lot considering this theme,but still cant make my code working. I have two tab separated files, I want to do the following thing: File 1: xx1 y yy xx2 y yy xx3 y yy xx4 y yy File 2: xx1 z1 xx2 z2 xx3 z3 xx4 z4 xx5 z5 So I want to merge them ,according to... (9 Replies)
Discussion started by: divergenciya
9 Replies

3. Shell Programming and Scripting

ksh/nawk help with if statement to choose between 2 files

Hi! I am having a bit of a problem with my script. There are two different date formats that may appear in a file, either Jul-12 or Jul--6. I tried to create an if statement that searches for one of the formats and if that doesn't exist searches for the other, however it doesn't seem to be... (3 Replies)
Discussion started by: ther2000
3 Replies

4. Shell Programming and Scripting

using nawk

help out with code. two files aaa bbb contains some records..output file xyz should be like this..see below i/p file:aaa 08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878 i/p file: bbb 60521|60510 o/p file :xyz 60510|08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878 (5 Replies)
Discussion started by: Diddy
5 Replies

5. Shell Programming and Scripting

match 2 files using nawk command

i am matching two files. the files are in the format file_1.txt 1|_|X|_| 2|_|W|_| 3|_|Y|_| 4|_|Z|_| 5|_|U|_| file_2.txt W|_|A|_| Z|_|C|_| V|_|B|_| X|_|D|_|sdff|_| Y|_| file_3.txt should be in the format (4 Replies)
Discussion started by: centurion_13
4 Replies

6. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

7. Shell Programming and Scripting

nawk help

What am I doing wrong here? I get syntax error. I am trying to parse a file looking for the lines with "running" as the first field then print the 5th field, then looking at the 9th field for specific values and writing the whole line to a junk file. nawk '; {if ($1 == "running")... (10 Replies)
Discussion started by: beppler
10 Replies

8. Shell Programming and Scripting

nawk Wert einer Variablen zur 2. Spalte eines Files addieren

wie kann ich zu dem 2. wert eines files den wert einer variable hinzufügen bei nawk? ich habe folgendes: nawk '{system("echo "$1" "$2+22)}' filename das funktioniert -> so wird beim zweiten wert 22 hinzugezählt! ich möchte aber nicht 22 hinzufügen sondern den wert, der in der variablen... (5 Replies)
Discussion started by: Helmut
5 Replies

9. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

10. Shell Programming and Scripting

Using NAWK to merge two files

Two files need to be joined on a second column. File 1 FRO FRONTIER MWC MIDWEST ORB ORBITZ ATR AIRTRAN BWI BESTWESTERN File 2 M AIRTRAN 8 TRIPS_YTD A M BESTWESTERN 8 ... (7 Replies)
Discussion started by: madhunk
7 Replies
Login or Register to Ask a Question