Shell Coding question for any experts out there


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Coding question for any experts out there
# 1  
Old 01-09-2004
Shell Coding question for any experts out there

Given this one long stream of data (all one line):

<TransactionDetail><TransactionHeader><ErrorLogging>YES</ErrorLogging><HistoryLogging>YES</HistoryLogging><ErrorDetection>NO</ErrorD
etection.0</LunKey><WorkingDir>/tlexmlt/xlate/i/10397</WorkingDir><JobName>I10397</JobName><ErrorCode>0</ErrorCode><ErrorMessage>EDI InboundRejects</ErrorMessage><GetNext>Y</GetNext><WorkStep>Xlati</WorkStep</ReplyItem></TransactionDetail>

How do I get this small piece of information back?

/tlexmlt/xlate/i/10397
# 2  
Old 01-09-2004
Well, I'm sure someone could come up with a nicer-looking way, but here's one solution:

echo "reallyLongLine" | awk -F"WorkingDir" '{print $2}' | sed -e 's=>==' -e 's=</=='

This splits your line into three parts, using the word "WorkingDir" as a field separator, so you have ">/tlexmlt/xlate/i/10397</" left.

Then the sed statement removes the carat symbols and the slash from the end.
# 3  
Old 01-09-2004
Code:
[qgatu003]/export/home/mxdooley$./test.pl file1
/tlexmlt/xlate/i/10397

[qgatu003]/export/home/mxdooley$cat test.pl
#!/usr/bin/perl -w

$file=shift;
open(FILE, "$file");
for (<FILE>) {
/\<WorkingDir\>(.*)\<\/WorkingDir\>/;
print "Working Directory: $1\n";
}

# 4  
Old 01-10-2004
Humm, this looks like an XML-compliant file to me.

Perhaps an XSL 'script' would be the better way
to process this type of file.

- Finnbarr
# 5  
Old 01-12-2004
Thanks for the replies everyone. I actually just used the SED example (first reply) and that worked like a charm. We do a lot of PERL scripting for my application, so reply 2 would have been fine as would have the XSL idea (we are a little lighter on XML knowledge), but I just implemented the first idea. Thanks everyone for the replies! Dave
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with understand shell script coding

Good afternoon everyone, I am very new to UNIX shell scripting and I am trying to understand the following code. I know what it does but I need to modify it so it will allow me to pass a file name as *FILENAME* Thank for any guidance offered. if ] ; then match=`expr "$file" :... (2 Replies)
Discussion started by: Walter Barona
2 Replies

2. Homework & Coursework Questions

UNIX script coding HW question

i am trying to write a script code in unix that will: 1. The problem statement, all variables and given/known data: display following menu to user: (A) Add (B) Subtract (C) Multiply (D) Divide (E) Modulus (F) Exponentiation (G) Exit Then ask user for choice (A-F). After taking... (5 Replies)
Discussion started by: renegade755
5 Replies

3. Shell Programming and Scripting

Need help in shell script coding

I have a file f1.txt that contains string: f1.txt aaa bbb ccc ... I want to write code to search that each string in file f2.txt(this file contains 1000+line codes). file f2.txt .. .. ....aaa...xyz.. ... ... ...ppp... (dots . can be characters ot blank spaces) If particular... (2 Replies)
Discussion started by: Sanchit
2 Replies

4. UNIX for Advanced & Expert Users

Experts!! please help me

Hi experts, Please help me on the below: how to write a shell script to search and delete files on windows server. -script runs on unix box -it should search for specific files on windows server and delete them periodically. (1 Reply)
Discussion started by: chpradeepch
1 Replies

5. Shell Programming and Scripting

NEED HELP FROM SHELL EXPERTS ASAP ..Compare of two files

I have seen the old forums before posting this thread...I did not find the designated answer for my shell script... I am novice in shell programming: Can some one help on how i can loop with in the loop when comparing two files... I need to compare ID in File1 with IDs in File2...If the ID... (1 Reply)
Discussion started by: rspotula
1 Replies

6. Shell Programming and Scripting

awk question for experts

Hi guys I am trying to perform a substitution using 'awk' command, but it fails. I work in ksh. Here is my code: $ line="F 18:30 10 23:00 ts1632back" $ n="ts1632back" $ m="18:45" $ echo ${line} | nawk -v a=$n -v b=$m '{if ($5==a) $2=m; print }' F 10 23:00 ts1632back $It should've... (2 Replies)
Discussion started by: aoussenko
2 Replies

7. Shell Programming and Scripting

Secure coding standards for Shell Programming

Hi, Can anyone point me to Secure coding standards for shell programming guides, links etc etc... Thanks and regards, Vamsi K Surampalli. (2 Replies)
Discussion started by: vamsisurampalli
2 Replies

8. Shell Programming and Scripting

usage of sed question for experts

I need a little help with sed. Basically, I need to parse out selections from the output of hddtemp so conky can display some hdd temps for me. I have hddtemp in daemon mode so A simple 'nc localhost 7634' displays the following: $ nc localhost 7634... (3 Replies)
Discussion started by: audiophile
3 Replies

9. Shell Programming and Scripting

Coding Standard For Unix Shell Scripting!!!

Is there any site on Coding Standard for Shell Scripting in UNIX. Please help me know!!!!! Thanks Om (1 Reply)
Discussion started by: Omkumar
1 Replies

10. UNIX for Advanced & Expert Users

Experts Only! Hard Question Ahead!!!!

SunOS5.8 is a radical departure from SunOs4.X in many ways. one of the important differences is the handling of devices. Adding devices under SunOS4.x required a kernel reconfiguration, recompliation and reboot. Under SunOS5.X, this has changed with the ability to add some drivers on the fly.... (1 Reply)
Discussion started by: Foo49272
1 Replies
Login or Register to Ask a Question