Parsing dynamic data from a command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing dynamic data from a command output
# 1  
Old 03-02-2010
Parsing dynamic data from a command output

Hi people,
I am writing a korn shell script, and one of the command gives an output something like below:
Code:
release.label.2010.03.02
objects: 
/project/path/to/some/file_name.ksh
/project/path/another/file_name01.dat

I have to retrieve the file paths one by one & use them as input for another command. any suggestions?

Would appreciate if someone can post a string parsing code for this.

Last edited by Scott; 03-03-2010 at 12:53 PM.. Reason: Code tags
# 2  
Old 03-02-2010
Quote:
Originally Posted by kiwin1000
...one of the command gives an output something like below:
--------------
release.label.2010.03.02
objects:
/project/path/to/some/file_name.ksh
/project/path/another/file_name01.dat
--------------
So you have something like this:

Code:
$ 
$ mycommand
release.label.2010.03.02
objects:
/project/path/to/some/file_name.ksh
/project/path/another/file_name01.dat
$ 
$

Quote:
...
I have to retrieve the file paths one by one
...
Code:
$ 
$ mycommand | grep -E "(ksh|dat)$"
/project/path/to/some/file_name.ksh
/project/path/another/file_name01.dat
$ 
$

Quote:
...
& use them as input for another command. ...
Code:
$ 
$ 
$ mycommand | grep -E "(ksh|dat)$" | myothercommand
I received /project/path/to/some/file_name.ksh; I am now going to open this file...
I received /project/path/another/file_name01.dat; I am now going to open this file...
$ 
$

tyler_durden
# 3  
Old 03-03-2010
Hi durden,
The output files cud be anything like .mp, .ksh, .dml. What I was thinking is I will put the output of the first command to a variable. so everything is in a string format now. So i need a logic now where I can retrieve the file paths & input them one by one in the 2nd command.

is there a way i can retrieve substring which starts with a char "/" & ending char the one before a space. i hope u getting what m trying to say. in that way i can looking for another "/" & retrieve the path
# 4  
Old 03-03-2010
Why dont you just redirect the o/p of the first command in a temp file, and then filter the ones and used as an i/p for the next command?
# 5  
Old 03-03-2010
yes I can do that as well, but whats the logic of filtering? cause All i want from that is the file paths. but it also displays other information like the release label & objects:
# 6  
Old 03-03-2010
We need to store the output of the first command to a temp file. filtering in the sense from the temp file we are going to extract the file names. We can extract it by using the regular expressions. And then we are going to pass it as an input for the second command. What is the issue in this?
# 7  
Old 03-03-2010
the issue is m a beginner to shell scripting. dont know the exact commands. would appreciate if some one cud post a script for it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare output of UNIX command and match data to text file

I am working on an outage script and I run a command from the command line which tells me the amount of generator failures in my market. The output of this command only gives me three digits to identify the site by. I have a master list of all sites in a separate file, call it list.txt. If my... (7 Replies)
Discussion started by: jbrass
7 Replies

2. UNIX for Dummies Questions & Answers

Parsing filenames - dynamic

I have requirement of parsing file names from given directory based on the pattern ( pattern will be parameter to script and can be any ). for example, user enterred 2 params : directory name : /dirname/ filename_pattern : *.dat_???? and there are 2 files in the directory as... (1 Reply)
Discussion started by: freakabhi
1 Replies

3. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

4. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (7 Replies)
Discussion started by: slatoms
7 Replies

6. Red Hat

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (1 Reply)
Discussion started by: slatoms
1 Replies

7. Shell Programming and Scripting

Parsing fields from class list files to use output with newusers command

Hello I am trying to develop a shell script that takes a text file such as this... E-mail@ Soc.Sec.No. *--------Name-----------* Class *School.Curriculum.Major.* Campus.Phone JCC2380 XXX-XX-XXXX CAREY, JULIE C JR-II BISS CPSC BS INFO TECH 412/779-9445 JAC1936 XXX-XX-XXXX... (7 Replies)
Discussion started by: crimputt
7 Replies

8. Shell Programming and Scripting

parsing output from a diff command...

hi, i have a script which pipes the output of a diff -rq command into a separate file/ it would read something like this: Files mod1/lala/xml/test1.txt and mod2/lala/xml/test1.txt differ Only in mod2/lala/xml: test2.txt What i need to do is to parse this file so i end up with just a... (5 Replies)
Discussion started by: kam
5 Replies

9. Shell Programming and Scripting

parsing output from ls command

I have to test the directory name which is obtained from for dir in `ls -l|grep $9 ' i need to check whether it is directory ( if yes, I have to check the first 3 character fo the directory how can I do that? Please help me thanks (3 Replies)
Discussion started by: ajaya
3 Replies

10. UNIX for Dummies Questions & Answers

Parsing XML dynamic data via awk?

I am trying to use a line of output in an XML file as input in another new XML file for processing purposes via a shell script. Since I am a newbie though, I'm not sure how to do this since the data is different everytime. I am using this technique with static data right now: echo -n "Running... (5 Replies)
Discussion started by: corwin43
5 Replies
Login or Register to Ask a Question