Help with extract particular part of data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with extract particular part of data
# 1  
Old 12-12-2011
Help with extract particular part of data

Input file
Code:
<data>
<temporary>qe2qrqerq
qwewqeqwrqwrq
qrerwrewrwer
</temporary>
</data>
<sample>@!@##%#</sample>
<info>12345</info>
<content>2313214141454</content>
<data>
<temporary>qe2qrqerq
qrerwrewrwer
</temporary>
<content>123214214523</content>
</data>
<sample>@!@##%#</sample>
.
.

Desired output file
Code:
<data>
<temporary>qe2qrqerq
qwewqeqwrqwrq
qrerwrewrwer
</temporary>
</data>
<data>
<temporary>qe2qrqerq
qrerwrewrwer
</temporary>
<content>123214214523</content>
</data>
.
.

I would like only extract those info in between ""<data> and </data>"
Thanks for any advice.
# 2  
Old 12-12-2011
What have you tried so far?
# 3  
Old 12-12-2011
Hi zaxxon,

Below is the way that I tried:
Code:
[home@perl]grep -v 'sample' input_file.txt | grep -v 'info' | grep -v 'content' > output_file.txt

But it seems like not a smart way to do that Smilie
# 4  
Old 12-12-2011
Code:
perl -ne '(/<data>/../<\/data>/)&&print $_' inputfile.txt

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 12-12-2011
With awk:
Code:
awk '/^<data>/ {print; f++; next} /^<\/data>/ {print; f--} f' infile

This User Gave Thanks to zaxxon For This Post:
# 6  
Old 12-12-2011
Another one with Perl -

Code:
$
$ cat f43
<data>
<temporary>qe2qrqerq
qwewqeqwrqwrq
qrerwrewrwer
</temporary>
</data>
<sample>@!@##%#</sample>
<info>12345</info>
<content>2313214141454</content>
<data>
<temporary>qe2qrqerq
qrerwrewrwer
</temporary>
<content>123214214523</content>
</data>
<sample>@!@##%#</sample>
$
$
$ perl -0lnE 'say $1 while(/(<data>.*?<\/data>)/sg)' f43
<data>
<temporary>qe2qrqerq
qwewqeqwrqwrq
qrerwrewrwer
</temporary>
</data>
<data>
<temporary>qe2qrqerq
qrerwrewrwer
</temporary>
<content>123214214523</content>
</data>
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help to extract part of the string

Hi, I have a string with name as 20140412-s1-Potopolive_promos_20140412. So I want to extract only Potopolive string. Could you please help me the command. O/p : Potopolive Thx in advance (5 Replies)
Discussion started by: lkeswar
5 Replies

2. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

3. Shell Programming and Scripting

Extract part of a string

I have a file with 100s of lines of text. I want to perform an extraction of this line: Info bpzs(pid=2652) using 1000 bits I have not been able to extract it. Should I try expr match or is there another method? This line has data both in front of and in back of it. I do not have grep -o... (5 Replies)
Discussion started by: newbie2010
5 Replies

4. Shell Programming and Scripting

how to extract a certain part of a line

Hi friends, I want to select and use the certain part of a line. For example I have the following line home/1245/hgdf/acsdf/myhome/afolder/H2O/endfile how can I extract the part " /myhome/afolder/H2O/endfile " thanks (6 Replies)
Discussion started by: rpf
6 Replies

5. Shell Programming and Scripting

How to extract one part from whole output

Hi All, I am trying to write a small shell programming to get db2 database size info. The command I am going to use is- db2 "CALL GET_DBSIZE_INFO(?, ?, ?, -1)" and the output of above command generally is- Value of output parameters -------------------------- Parameter Name :... (4 Replies)
Discussion started by: NARESH1302
4 Replies

6. Shell Programming and Scripting

extract last part of string.

Hi, I have a string like this BUNDLE=/home/bob/flx/user.bun how to extract only the the last part ie, only user.bun (2 Replies)
Discussion started by: vprasads
2 Replies

7. UNIX for Dummies Questions & Answers

How to get data only inside polygon created by points which is part of whole data from file?

hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Discussion started by: reva
7 Replies

8. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

9. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

10. UNIX for Dummies Questions & Answers

Extract a part of file name

Hi, I want to extract a part of filename and pass it as a parameter to one of the scripts. Could someone help. File name:- NLL_NAM_XXXXX.XXXXXXX_1_1.txt. Here i have to extract only XXXXX.XXXXXXX and the position will be constant. that means that i have to extract some n characters from... (6 Replies)
Discussion started by: dnat
6 Replies
Login or Register to Ask a Question