Another data extraction question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another data extraction question
# 1  
Old 12-23-2008
Another data extraction question

Hi,

I have a tmp file like below:

Code:
<ADATA>
 ANUM=900
ADESC=Saving
ATYP=0
TXREGD=0
</ADATA>
 
<ADATA>
ANUM=890
ADESC=Saving
ATYP=0
ABAL=9000
TXREGD=1
</ADATA>
 
<ADATA>
 ANUM=900
ADESC=Check
ATYP=1
</ADATA>
 
<ADATA>
ANUM=890
ADESC=Saving
ATYP=0
ABAL=9000
TXREGD=1
</ADATA>

From above <ADATA> and </ADATA> container, I need ANUMs which has TXREGD only.

Last edited by vgersh99; 12-24-2008 at 06:06 PM.. Reason: code tags, PLEASE!
# 2  
Old 12-23-2008
Code:
awk '
  BEGIN { RS=""; ORS = "\n\n" }
  /TXREGD/ ' "$FILENAME"

# 3  
Old 12-23-2008
Power

I am new to Unix, can you please explain me what is RS and ORS stands for.
I need ANUMS and TXREGD fields from each <ADATA> and </ADATA> container.
# 4  
Old 12-23-2008
Quote:
Originally Posted by kunigirib
I am new to Unix, can you please explain me what is RS and ORS stands for.
User-modified Variables - Awk User Guide
# 5  
Old 12-23-2008
Quote:
Originally Posted by kunigirib
I am new to Unix, can you please explain me what is RS and ORS stands for.

Record Separator and Output Record Separator
Quote:
I need ANUMS and TXREGD fields from each <ADATA> and </ADATA> container.

Code:
awk '
  BEGIN { RS="" }
  /TXREGD/ ' "$FILENAME" | grep -e ANUMS -e TXREGD

# 6  
Old 12-24-2008
cat tmp.file | grep -e ANUM -e TXREGD

gives me all ANUMs and TXREGDs.

But I need ANUMs which has TXREGD only.

And I should know which ANUM has which TXREGD.

Ex:
ANUM=900
TXREGD=0


ANUM=890
TXREGD=1


Thanks
# 7  
Old 12-24-2008
Quote:
Originally Posted by kunigirib
cat tmp.file | grep -e ANUM -e TXREGD

There's no need for cat.

Code:
grep -e ANUM -e TXREGD tmp.file

Quote:
gives me all ANUMs and TXREGDs.

But I need ANUMs which has TXREGD only.

Did you try the script I posted?
Quote:

And I should know which ANUM has which TXREGD.

Ex:
ANUM=900
TXREGD=0


ANUM=890
TXREGD=1

Code:
 awk '
  BEGIN { RS=""}
  /TXREGD/ ' "$FILE"  |
 awk '/ANUM/ { print } /TXREGD/ { print; print ""}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Data extraction from .txt file

Hey all, i´ve got the following problem: i´m aquiring data with an instrument and i get data in a .txt file. This is how the txt file looks like: Report of AU program poptau F1P=-49.986ppm F2P=-110.014ppm Target directory for serfile: D:/data/Spect500/nmr/Thoma/882 Linear... (17 Replies)
Discussion started by: expikx
17 Replies

2. UNIX for Dummies Questions & Answers

Need help for data extraction if files

Hello all, I want to extract some particular data from a files and than add all the values . but i m not able to cut the particular word(USU-INOCT and USU-OUTOCT) as it is coming not in column. and than able to add values coming in it . can anyone help me Please cat <file name> ... (7 Replies)
Discussion started by: anamdev
7 Replies

3. Shell Programming and Scripting

data extraction from a file

Hi Freinds, I have a file1.txt in the following format File1.txt I want to get 2 files from the above file filextra.txt should have the lines which are ending with "<" and remaining lines in the filecompare.txt file. Please help. (3 Replies)
Discussion started by: i150371485
3 Replies

4. Shell Programming and Scripting

Data Extraction problem in perl

Hello, I want to extract the words from a file which starts with SRD-R or SRD-DR. I have written a script which is able to trace the word but it is printing the whole line. sub extract_SRD_tag{ my ($tag, $app, $path, @data, $word ); $path = shift; $app = shift; open (FILE, $path) or... (2 Replies)
Discussion started by: suvendu4urs
2 Replies

5. Shell Programming and Scripting

Data extraction in perl variable

HI, i have variable in perl like below $tmp="/home/sai/automation/work/TFP_GN.txt" it can conatain any path its filled from config file. now i want extarct the path upto this /home/sai/automation/work/ and put it in another variable say... (4 Replies)
Discussion started by: raghavendra.nsn
4 Replies

6. Shell Programming and Scripting

Data and return code extraction

Hello everybody, Another day another problem. I have to create a script which collects data from 3 csv files. I would like the script to check file1 which contains different values for the date entered previously. As you can see 01/12/2010 contains actions in the first field and in the... (7 Replies)
Discussion started by: freyr
7 Replies

7. Shell Programming and Scripting

Selective extraction of data from a files

Hi, I would like to seek for methods to do selective extraction of line froma file. The scenario as follows: I have a file with content: message a received on 11:10:00 file size: 10 bytes send by abc message b received on 11:20:00 file size: 10 bytes send by abc (3 Replies)
Discussion started by: dwgi32
3 Replies

8. Shell Programming and Scripting

Data Extraction From a File

Hi All, I have a requirement where I have to search the file with some text say "Exception". This exception word can be repeated for more then 10 times. Suppose the "Exception" word is repeated at line numbers say x=10, 50, 60, 120. Now I want to extract all the lines starting from x-5 to... (3 Replies)
Discussion started by: rrangaraju
3 Replies

9. Shell Programming and Scripting

help with data extraction script

Hello all, Iam newbie here and to unix programming. I have the following text file. A:Woshington,B:London,C:Paris,D:Manchester,C:Lisbon,E:Cape town. Now I would like extract this and store in database. here is the script I have tried but it did work. CITY1:`echo "$text" | grep "A:"... (11 Replies)
Discussion started by: mam
11 Replies

10. Shell Programming and Scripting

Data Extraction issue.

I have a small problem, I have written a following script, which extracts all the rows from source file which strats with T101 and rights it to another file mydata.dat Script my_script #!/bin/ksh YMONTH=$1 dir1='/home/data' dir2='/clients/source_file' cd $dir1 grep "T101"... (5 Replies)
Discussion started by: irehman
5 Replies
Login or Register to Ask a Question