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
# 8  
Old 03-03-2010
In a simplified format...can be optimized..

Assuming you have redirected the o/p of the first command to a file name "file".

Code:
#!/bin/sh

while read line
do
first=$( echo $line | cut -c 1 )
if [ $first == "/" ]; then
  echo $line
fi
done < file


cheers,
Devaraj Takhellambam
# 9  
Old 03-03-2010
consider that you are redirected your output of the first command to a file called output1

So the content of the output1 file will be as follows

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

To extract the files from that you can use the following commands

Code:
cat test | grep "^/.*\.*" test

So now it will extract the file names from that output and will give the following as the result
Code:
/project/path/to/some/file_name.ksh
/project/path/another/file_name01.dat

Now you can pass the above result to the third command using pipe
# 10  
Old 03-03-2010
i was trying that but was told not to create any files. So now i put the output in a variable.
I tried this code using Devtakh's idea & it worked:
Code:
for v in ${var1}
do
   first=$( echo $v | cut -c 1 )
   if [ $first == "/" ]; then
        mycommand $v
   fi
done

Thanks people. Smilie

Last edited by Scott; 03-03-2010 at 12:53 PM.. Reason: Code tags please...
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