Multiple Substring Outputs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Multiple Substring Outputs
# 1  
Old 04-15-2010
Multiple Substring Outputs

Hello,

I am reading a file with millions of lines in it. Each line is big line containing several xml tags. I need to Output just the value of two tags in a seperate flat file.

For eg- I need to output whats present in <ComponentName> something </ComponentName> and another tag is <ElapsedTime>362</ElapsedTime>.

Currently i am handling this in 3 steps-

1. Reading full file for capturing all component names- Using Awk
2. Then again reading full file for all Elapsed Times - Using Awk
3. And then Finally using paste command to merge output of above

I intend do all above in 1 step only.

That is capturing both component name and elapsed time simulatneously and writing them into different columns in a file.

So this will save some time.

Can somebody pls guide on how to take multiple subsets out of a string at one go.

Any help would be much appreciated.

Thanks,
Sunny.
# 2  
Old 04-16-2010
Maybe something like that? I'm not sure if it will work with a file. Test it.

Code:
echo "<ComponentName> something </ComponentName> asdfdf werwer <ElapsedTime>362</ElapsedTime>" | grep -o -E '((<ComponentName>)(.*)(</ComponentName>))|((<ElapsedTime>)(.*)(</ElapsedTime>))' | tr  "<|>|/" "\t" | awk '{print $2}' | fmt -s

# 3  
Old 04-16-2010
Somehow, my shell is not recognizing "-o" option with grep.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Consolidating multiple outputs in one file

Dears, i am stuck here i have 3 scripts running at one time and all the three scripts finish at different time and each script generate 1 file with different name. so i will have three files. i dnt know which script finish first i want to have a script which check if all the there files are... (6 Replies)
Discussion started by: mirwasim
6 Replies

2. Shell Programming and Scripting

Returning multiple outputs of a single line based on previous repeated lines

Hello, I am trying to return a time multiple times from a file that has varying output just before the time instance, i.e. cat jumped cat jumped cat jumped time = 1.1 cat jumped cat jumped time = 1.2 cat jumped cat jumped time = 1.3 In this case i would like to output a time.txt... (6 Replies)
Discussion started by: ryddner
6 Replies

3. UNIX for Dummies Questions & Answers

Writing multiple outputs in to separate cells of CSV file

Hi I am writing a script which has multiple awk statements and each statement gives me a numeric count as an output. I want those output to be stored in different cells of a csv file. say 12 awk statements give 12 output and i want them in diffrenet cells of csv file. Thank you guys..!! (4 Replies)
Discussion started by: prabhat.diwaker
4 Replies

4. Shell Programming and Scripting

Array in awk outputs multiple values

Disclaimer: OP is 100% Awk beginner. I use this code on ASCII files I need to report against. awk 'BEGIN { tokens = 0 tokens = 0 tokens = 0 } { for (token in tokens) { if ($1 == token){print $0; tokens++;}}} END {for (token in tokens){ if( tokens ==... (1 Reply)
Discussion started by: alan
1 Replies

5. Shell Programming and Scripting

awk with multiple regex and substring

Hi Experts, I have a file on which i want to print the line which should match following criterias. Line should not start with 0 or 9 and Line should start with 1 and ( 576th character should not be 1 or 2 or 576-580 postion should not be NIPPF or CDIPB or 576-581 postion should... (2 Replies)
Discussion started by: millan
2 Replies

6. Shell Programming and Scripting

simple join for multiple files and produce 3 outputs

sh script file1 filea fileb filec ................filez. >>output1 & output2 &output3 file1 z10 1873 1920 z_number1_E59 z10 2042 2090 z_number2_E59 Z22 2476 2560 z_number3_E59 Z22 2838 2915 z_number4_E59 z1 1873 1920 z_number1_E60 z1 ... (9 Replies)
Discussion started by: stateperl
9 Replies

7. UNIX for Dummies Questions & Answers

multiple variables assignement (stdout/stderr outputs)

Hi all, I've been looking around for this for a while and can't seem to find a satifactory way to do what I want: I would like to assign the output of stdout to a variable and that of stderr to another one, and this without using temporary files/named pipes. In other words be able to assign... (4 Replies)
Discussion started by: anthalamus
4 Replies

8. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

9. Shell Programming and Scripting

How to store multiple outputs from an awk command?

x=`echo $line | awk -F "|" '{print $1;print NR}'` How will I get the 2 return values ($1 and NR) from awk to variables? (4 Replies)
Discussion started by: tene
4 Replies

10. Shell Programming and Scripting

compare 2 outputs

Hello, I have a shell script that is used as follows: ./script -s <Oracle_server_name> the script returns several lines in this format: parameter name required value Current Value comments --------------- ------------- -------------- --------- My objective now is to compare 2... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies
Login or Register to Ask a Question