Help reqd in shell scripting..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help reqd in shell scripting..
# 1  
Old 05-10-2011
Help reqd in shell scripting..

Hi guys,
I am new to shell scripting and I need urgent assistance.
I have an xml like :
Code:
<AgreementNumberFull>13-WY-84252</AgreementNumberFull>
<AgreementNumberAbbr>WY84252</AgreementNumberAbbr>
<LineOfBusiness>F</LineOfBusiness>
<CompanyCode>0005</CompanyCode>
<UniqDigit/>
<StateCode/>

I need to write a shell script which parses this xml and returns the value of tags in stringdata type. If the value of the tag is null(eg:UniqDigit) then response string should be '0'

For example: The output for the above xml should be:
Code:
13-WY-84252
WY84252
F
0005
0
0.

Please help me with this.Thanks in advance.

Last edited by Franklin52; 05-11-2011 at 08:26 AM.. Reason: Please use code tags
# 2  
Old 05-10-2011
Try this

Code:
awk -F'<|>' '{$0=$3}$0==""{$0=0}1' infile

regards,
Ahamed
# 3  
Old 05-11-2011
Thanks Ahmed.. But am getting this error :
awk: syntax error near line 1
# 4  
Old 05-11-2011
Code:
 cat test.txt |awk -F '>' '{print $2}' | awk -F '<'  '{ if (  $2 == "" ) print "0";else print $1 }'

# 5  
Old 05-11-2011
hi Palanisvr,
thanks for the reply..

my script is like this as u said:
Code:
#!/bin/sh 
cat test.txt | awk -F '>' '{print $2}' | awk -F '<'  '{ if (  $2 == "" ) print "0";else print $1 }'

But am getting the error:
Code:
awk: syntax error near line 1
awk: bailing out near line 1
awk: syntax error near line 1
awk: bailing out near line 1

Please help

Last edited by Franklin52; 05-11-2011 at 08:26 AM.. Reason: Please use code tags
# 6  
Old 05-11-2011
on which flavour of linux you are executing the code.

Code is working for me as below.

Code:
$ uname -a
Linux  x86_64 x86_64 x86_64 GNU/Linux
$ cat test.txt |awk -F '>' '{print $2}' | awk -F '<'  '{ if (  $2 == "" ) print "0";else print $1 }'
13-WY-84252
WY84252
F
0005
0
0

# 7  
Old 05-11-2011
hi again,

am running the code on this :
Code:
# uname -a
SunOS tc95air3 5.10 Generic_139555-08 sun4u sparc SUNW,Sun-FireV-245


Last edited by Franklin52; 05-11-2011 at 08:27 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Explanation reqd

Hi, i have a script of following content #!/usr/bin/sh 'exit 255' USR1 ncm_CheckDir.pl -a /cnt/mgr/test/working/applog_CheckDir.log -c /cnt/mgr/test/lib/config/bp_CheckDir.conf -s /cnt/mgr/test/log/syslog filename : BC_CheckDir when i execute ie : sh BC_CheckDir i am getting... (11 Replies)
Discussion started by: psthariharan
11 Replies

2. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

3. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

4. Shell Programming and Scripting

Shell Script - help Reqd

Hi, I need someone's help in writing a shell script. Since am very new i am stuck . I have 2 files in the same dir. ============================================== FileA Table1~07/07/2009 00:00:00~4 Table1~07/06/2009 00:00:00~41 Table1~07/08/2009 00:00:00~4 ... (8 Replies)
Discussion started by: vijayarajvp
8 Replies

5. Shell Programming and Scripting

shell script reqd - deleting files

I have written a script that deletes files: Requirement: i need to delete the files and to know how many files are deleted i.e the count of files and even i need to display when the started time of deletion and the ending time of deletion. I need to display these two times. script: ... (2 Replies)
Discussion started by: venkatesht
2 Replies

6. Shell Programming and Scripting

unix shell script reqd...

Task: Short Description: To find the files in a particular directory for the previous day, sort them by date and time and e-mail it across to a particular id. And the time is divided into eight fields and based on the time the respective field should be updated with the flag 1. Eight... (7 Replies)
Discussion started by: venkatesht
7 Replies

7. Shell Programming and Scripting

AWK help reqd

Hi, I have below requirement that I need to do it using AWK. Files ==== File1: data file that has thousands of recs File2: Lookup file I need to compare the position 21-31 of File1 with 1-11 of File2. If matched then write to new output file(outfile1) else write to another output... (17 Replies)
Discussion started by: Sathy153
17 Replies

8. Shell Programming and Scripting

Checklist for Shell Script reqd

Hi, Can anyone provide me with the Code Review Checklist for Shell scripts ?? Thanks in advance. (2 Replies)
Discussion started by: Shivdatta
2 Replies

9. HP-UX

Help Reqd

Hi I am facing the problem where my HP Unix system date is in accordance with the current date but the logs written by the same is of previous time stamp. Eg. System Date - Thu Mar 15 18:00:04 IST 2007 Syslogs - Mar 15 12:30:10 mac@1 ftpd: FTP LOGIN FROM xx.xxx.xxx.xx , main The ftp... (1 Reply)
Discussion started by: PradeepRed
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question