Details within file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Details within file
# 1  
Old 08-06-2012
Details within file

Hi,

I am trying to write a script with goes through thousands of XML documents to pull out the values for a particular tag to a .txt file.

For example I have
Code:
file1.xml
file2.xml
file3.xml
.
.
.

fileN.xml

All these files have a tag called <systemID>.
The value that sits within these tags varies with every .xml file.

required output should just list all the values that sit within the <systemID> tag

Please assist how I will be able to achieve this goal

Regards


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-06-2012 at 08:34 AM.. Reason: code tags
# 2  
Old 08-06-2012
try this.....

Code:
for i in *.xml
do
echo $i
grep "<systemID>" $i | awk -F "[<>]" '{ print $3 }'
done

# 3  
Old 08-06-2012
Try this :

Code:
 
grep "<systemID>" file*.xml | cut -d">" -f2- | cut -d"<" -f1 > a.txt

# 4  
Old 08-06-2012
Thanks for the response..

What if i was looking for all the systemID values in a scenario like the one below:

Code:
<address type="go" systemID="123456" uniqueId="0023184" value="123"/>


Last edited by Scott; 08-06-2012 at 08:47 AM.. Reason: Code tags
# 5  
Old 08-06-2012
Quote:
Originally Posted by Chor419
Thanks for the response..

What if i was looking for all the systemID values in a scenario like the one below:

<address type="go" systemID="123456" uniqueId="0023184" value="123"/>
Code:
 awk -F '"' '{ print $4 }'

# 6  
Old 08-06-2012
Can also try this, if it is not at a fixed field position:
Code:
$ echo '<address type="go" systemID="123456" uniqueId="0023184" value="123"/>'| sed 's/.*systemID="\?\([^" ]*\)[" ]\?.*/\1/g'
123456

Used GNU sed.
# 7  
Old 08-06-2012
Code:
awk 'match($0,/systemID="[^"]*"/){
print FILENAME,substr($0,RSTART+10,RLENGTH-11)}' *.xml

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract sentence and its details from a text file based on another file of sentences

Hi I have two text files. The first file is TEXTFILEONE.txt as given below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (7 Replies)
Discussion started by: my_Perl
7 Replies

2. Emergency UNIX and Linux Support

Getting details from sudoers file

Hi, I need the details of which ids belong to the sudoers file, and which groups these ids belong to. Can anyone suggest a way to derive that information into a flat file please? G (4 Replies)
Discussion started by: ggayathri
4 Replies

3. Shell Programming and Scripting

Getting file Details with find -mmin

I'm new to this and I have done a lot of research and am 99% done with my ksh script BUT I need help with. The script looks at Journal files and reports back on any that have not been updated for 15 min. Everything works but I wanted more detail (added -ls) and now I'm getting dups. Original code:... (2 Replies)
Discussion started by: blackopz
2 Replies

4. UNIX for Dummies Questions & Answers

at -l doesnt give details of the scheduled job. How to get the details?

I have scheduled couple of shell scripts to run using 'at' command. The o/p of at -l is: $ at -l 1320904800.a Thu Nov 10 01:00:00 2011 1320894000.a Wed Nov 9 22:00:00 2011 1320876000.a Wed Nov 9 17:00:00 2011 $ uname -a SunOS dc2prcrptetl2 5.9 Generic_122300-54 sun4u sparc... (2 Replies)
Discussion started by: superparticle
2 Replies

5. Shell Programming and Scripting

Extract details from XML file

Hi , I have one xml file contains more than 60 lines. I need to extract some details from the file and store it in new file.Not the whole file Please find the xml file below: <?xml version="1.0" encoding="UTF-8"?> <DeploymentDescriptors xmlns="http://www.tibco.com/xmlns/dd"> ... (6 Replies)
Discussion started by: ckchelladurai
6 Replies

6. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

7. UNIX for Dummies Questions & Answers

cut file details from the path given

Hi, Filenames come as /DataStage/temp/ERT/infile/RU.ER.09.0106.txt in a file. I want to cut first 2 chars of the filename like RU, then next 2 like ER and next like 09 I tried using var=/DataStage/temp/ERT/infile/RU.ER.09.0106.txt echo $var|cut -f 1 -d .(dot) this gives... (2 Replies)
Discussion started by: harshada
2 Replies

8. Shell Programming and Scripting

i want to extract details for particular file

Hi i have following file uuid ( RO) : 62701790-60da-dd9a-669d-a563aac1c435 host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed sr-uuid ( RO): 62103d07-e0aa-acf3-2d9f-414ad3377bd0 device-config (MRO): location: /dev/xapi/block ... (6 Replies)
Discussion started by: bp_vardhaman
6 Replies

9. UNIX for Dummies Questions & Answers

Details on the ls command and file types

Hey y'all, I need some help with the nitty gritty of the ls command. -First off in the man pages in the -l mode the first character can be "door" can anyone tell me what a door is??? -also in the -l mode the first character can be "fifo"or"pipe" can anyone tell me what a this is??? -What... (4 Replies)
Discussion started by: jacob358
4 Replies

10. HP-UX

What file contains boot up init details?

I want to get my telnetd to run on startup and was wondering where it was? im used to having it in /etc/init.d/rc.d but it is not the same in hp-ux :( thanks all (4 Replies)
Discussion started by: emplate
4 Replies
Login or Register to Ask a Question