Substitution Issue with nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substitution Issue with nawk
# 1  
Old 07-17-2013
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:

Code:
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 0.

OS is Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC

Thanks,
Mark

Last edited by Scott; 07-17-2013 at 01:48 PM.. Reason: Please use code tags
# 2  
Old 07-17-2013
Hi.

The replacement should be a string, not a regular expression:

Code:
$ nawk '{gsub(/</,">\n"); print}' test.raw > test.xml

This User Gave Thanks to Scott For This Post:
# 3  
Old 07-17-2013
Perfect!

Thanks - now all I need to do is swap the order so the newline comes before the "<".

---------- Post updated at 11:30 AM ---------- Previous update was at 10:43 AM ----------

I got it to work in three separate nawk command lines. Any way to concat them into a single command line?
set 1 - process occurences of &gt;&lt;
Code:
nawk '{gsub(/&gt;&lt;/,">\n<"); print}' test.raw > test.xma

set 2 - process occurences of &gt;
Code:
nawk '{gsub(/&gt;/,">"); print}' test.xma > test.xmb

set 3 - process occurrences of &lt;
Code:
nawk '{gsub(/&lt;/,"<"); print}' test.xmb > test.xml


Last edited by Scott; 07-17-2013 at 03:35 PM.. Reason: Please use code tags
# 4  
Old 07-17-2013
Quote:
Originally Posted by sffuji
Thanks - now all I need to do is swap the order so the newline comes before the "<".

---------- Post updated at 11:30 AM ---------- Previous update was at 10:43 AM ----------

I got it to work in three separate nawk command lines. Any way to concat them into a single command line?
set 1 - process occurences of &gt;&lt;
Code:
nawk '{gsub(/&gt;&lt;/,">\n<"); print}' test.raw > test.xma

set 2 - process occurences of &gt;
Code:
nawk '{gsub(/&gt;/,">"); print}' test.xma > test.xmb

set 3 - process occurrences of &lt;
Code:
nawk '{gsub(/&lt;/,"<"); print}' test.xmb > test.xml

Code:
nawk '
{        gsub(/&gt;&lt;/,">\n<")
         gsub(/&gt;/,">")
         gsub(/&lt;/,"<")
         print
}' test.raw > test.xml

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

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

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

4. Shell Programming and Scripting

Issue with substitution using sed

Hi all Having issue with substitution using sed Trying to assign the absolute path of the file to the variable 'floc' returned by the find command floc=`find / -name $fname` eg cat $floc '/root/samplecheck/myfile' I want to replace '/' with '->' in the 'floc' i am using the below sed... (2 Replies)
Discussion started by: amithsebkanattt
2 Replies

5. Shell Programming and Scripting

issue with toupper in nawk

Hi All, I am seeing an issue while using toupper in nawk. Below is the code that I am using.Toupper method is not working as expected in this case.nawk 'NR==FNR{a=$4" "$5}NR>FNR{print NF?$0:a"\n";if(/^cn:/) x=toupper($0)}' FS="" id_list.txt attributes.txt > out In the above script, id_list... (9 Replies)
Discussion started by: Samingla
9 Replies

6. Shell Programming and Scripting

sed pattern substitution issue?

Hello everyone ... I'm going crazy, I hope some of you can help me ... I have to replace a line in a crontab like this: 5 2 * * 2 root backupdat with this: 5 5 * * 3 root backupdat the command I use is the following: sed -i.bak -e 's/5 2 * * 2 root backupdat/5 5 * * 3 root... (4 Replies)
Discussion started by: ionral
4 Replies

7. Shell Programming and Scripting

Issue in substitution

Hi , I have have file which has following structure 01aaaa88888000-9999 01ssss77777000-0991 01ssss7777700000991 02ssss7777700000991 The record 01 is corrupt as value from 12th field to 19th should be positive or start with - however it is 000-9999 it should be -0009999 i need to... (4 Replies)
Discussion started by: test_user
4 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

encrytion/substitution issue in a file

1) ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547425069636596::6:N:mrs charles:N:PH:00010031:0001' OUTPUT - ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547******636596::6:N:mrs charles:N:PH:00010031:0001' The... (5 Replies)
Discussion started by: mad_man12
5 Replies

10. Solaris

Variable Substitution Issue

#!/bin/ksh VAR_ONE=HELLO TEMP=ONE echo $VAR_${TEMP} ## Output is: ONE Hi, I want the output to echo HELLO and not ONE as the above script does. I know I am missing something with dollar substitution. Can anyone help me out ? Thanks. Cal (4 Replies)
Discussion started by: calredd
4 Replies
Login or Register to Ask a Question