issue with toupper in nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue with toupper in nawk
# 8  
Old 04-22-2011
Hi Franklin,
The code is adding the string but after records, the code is placing wrong id values. I mean code is adding id value of some other cn. I am working on a 45mb file.

Thanks,
Sam
# 9  
Old 04-22-2011
Isn't this what you expect?
Code:
$ cat id_list.txt
cn: abc, id: 111
cn: DEF, id: 222
cn: ghi, id: 333
cn: JKL, id: 444
$ cat attributes.txt
gn: abc
cn: abc
objclass: test
uid: abc
 
gn: DEF
cn: DEF
objclass: test
uid: DEF
 
gn: EGH
cn: EFG
objclass: test
uid: EFG
 
gn: ghi
cn: ghi
objclass: test
uid: ghi
 
gn: JKL
cn: JKL
objclass: test
uid: JKL
$
$ nawk -F"[ ,]" 'NR==FNR{a[toupper($1$2)]=$4 OFS $5; next}
{idx=toupper($1$2)}
idx in a {u=a[idx]}
u && /uid:/{$0=$0 RS u RS "xxx: mno"; u=""}
1' id_list.txt  attributes.txt
gn: abc
cn: abc
objclass: test
uid: abc
id: 111
xxx: mno
 
gn: DEF
cn: DEF
objclass: test
uid: DEF
id: 222
xxx: mno
 
gn: EGH
cn: EFG
objclass: test
uid: EFG
 
gn: ghi
cn: ghi
objclass: test
uid: ghi
id: 333
xxx: mno
 
gn: JKL
cn: JKL
objclass: test
uid: JKL
id: 444
xxx: mno
$

# 10  
Old 04-22-2011
The code is working fine for some records. I am seeing different behavior if I run the same agains huge file. Id values in output file are not in sync with the id values in id list file.

Thanks,
Sam
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

Substitution Issue with nawk

Hi, I'm trying to reformat some badly formatted XML that I've extracted from Oracle clob columns using the following nawk command: nawk '{gsub(/</,/>\n/); print}' test.raw > test.xml the substitution executes fine, but instead of subbing < with > followed by newline, it subs the < with a... (3 Replies)
Discussion started by: sffuji
3 Replies

3. Shell Programming and Scripting

issue with nawk while using variable assignment

#ifconfig -a | nawk '/1.1.1.1/{print}' inet 1.1.1.1 netmask xxxxxxxxx broadcast 0.0.0.0 If i assign the ip to a variable and search for the variable nothing gets printed!! # ifconfig -a | nawk -v ip=1.1.1.1 '/ip/{print}' I am not able to understand why this is happening! (6 Replies)
Discussion started by: chidori
6 Replies

4. UNIX for Dummies Questions & Answers

Awk Help - toupper/tolower

Hi, I am learning awk and faced few queries. Kindly suggest on the same. Where it is wrong. $ awk '{if (toupper($1) ~ /a/) print $0}' inv $ awk '{if (toupper($1) ~ /A/) print $0}' inv -- Why this output Jan 13 25 15 115 Mar 15 24 34 228 Apr 31 52 63 420 May 16 34 29 208... (6 Replies)
Discussion started by: vanand420
6 Replies

5. Shell Programming and Scripting

nawk issue

Hi, Below work fine, whenever any character puts, however if we use "(", it's not working. Working =============== echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print substr($1,1,match($1, "u"))}' Not working ==================== echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print... (3 Replies)
Discussion started by: sbaisakh
3 Replies

6. Shell Programming and Scripting

toupper or tolower case of first letter of the line depending on another file

Hi I would like to read if the first letter of a line in a first file (gauche.txt) is uppercase or lowercase, and change consequently the first letter of the corresponding line in the second file (droiteInit.txt). I have done this but it won't work (I launch this using gawk -f... (16 Replies)
Discussion started by: louisJ
16 Replies

7. 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

8. Shell Programming and Scripting

grep / nawk issue

I have a report which contains the following: Count Value % 47 69.12 18 26.47 3 4.41 I want to grep the total on the bottom brackets and store in a variable. However this may have a different figure everyday. To read the i do: ... (1 Reply)
Discussion started by: Pablo_beezo
1 Replies

9. Shell Programming and Scripting

Handling multiple fields of a database file for toupper() function in awk

hello everyone.... script is: To convert the contents of a database file into uppercase my code is: printf "%s\n" , $2 | awk '{print toupper($2)}' emp.lst i m able to do only for one field.....didn't get any sources for handling multiple fields. please suggest me for multiple... (1 Reply)
Discussion started by: Priyanka Bhati
1 Replies

10. 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
Login or Register to Ask a Question