Extract fields from different rows.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract fields from different rows.
# 15  
Old 02-24-2012
Quote:
Originally Posted by chetan.c
Filename is being printed but PCNAME is not getting printed.
Thanks.
Does your file have a line with the pattern "PCNAME="?

Please provide a sample of your input file.
# 16  
Old 02-24-2012
Sorry my mistake was giving PCNAME with wrong spelling.

Thanks guys.This was my second post here and this made my day!! SmilieSmilie

---------- Post updated at 04:20 AM ---------- Previous update was at 03:57 AM ----------

Just one more part to this.
[HEADER 0]
SID=D6EB96CC0
HID=9C246D6
CSource=xya
Cappe=1
Versionc=3670
[header1]
MAR1=STL
MARS2=STL
[HEADER 2]
REQ_BUFFER_ENCODING=UTF-8
REQ_BUFFER_ORIG_ENCODING=UTF-8
RESP_BODY_ENCODING=UTF-8
CON_ID=2713
[xml]
<Req>
....
....
......</Req>

How can I pick up the XML portion too.It will always appear under a tag like [xml] but will not necessarily begin with <Req> or end with </req>

Thanks!
# 17  
Old 02-24-2012
sed

Hi,

Try this one,

Code:
echo "<xml>This is a sample text</xml>" | sed 's/\<.*\>\(.*\)\<\/.*\>/\1/g'


Cheers,
RangaSmilie
# 18  
Old 02-24-2012
Code:
 
#!/bin/bash
cd /home/files
for i in *.txt
do
awk 'BEGIN {print FILENAME} /PCNAME=/ || /URL=/' "$i"
awk '/<.*/ , /.*<\/.*>/' "$i"
done

# 19  
Old 02-24-2012
It works perfectly!!

Just a doubt which is better in terms of performance; an awk oneliner or running it in a for loop.?

Can both the statements be combined?

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

2. Shell Programming and Scripting

awk to grep rows by multiple fields

Hello, I met a challenge to extract part of the table. I'd like to grep the first three matches based on field1 and field2. Input: D A 92.85 1315 83 11 D A 95.90 757 28 3 D A 94.38 480 20 7 D A 91.21 307 21 6 D A 94.26 244 ... (6 Replies)
Discussion started by: yifangt
6 Replies

3. Shell Programming and Scripting

To extract selected rows

Hi, I have two files Input1.txt and Input2.txt and i need to have a output with selected lines starting with the values present in Input2.txt. For example: Input1.txt:... (5 Replies)
Discussion started by: bhas
5 Replies

4. Shell Programming and Scripting

Remove rows with first 4 fields duplicated in awk

Hi, I am trying to use awk to remove all rows where the first 4 fields are duplicates. e.g. in the following data lines 6-9 would be removed, leaving one copy of the duplicated row (row 5) Borgarhraun FH9822 ol24 FH9822_ol24_m20 ol Deformed c Borgarhraun FH9822 ol24 ... (3 Replies)
Discussion started by: tomahawk
3 Replies

5. UNIX for Dummies Questions & Answers

extract specific rows

Hi I have a file that looks like the one below. For the same 'TCONS' in the second column, I would like to extract the row that has the highest (or last) number in the fourth column. Any kind of help will be appreciated. input transcript_id "TCONS_00000051"; exon_number "1"; transcript_id... (4 Replies)
Discussion started by: jdhahbi
4 Replies

6. Shell Programming and Scripting

Replacing certain fields from certain rows

Hi all, say for example i have the next input file 30 Au 7.500000 7.500000 5.774000 Au 7.500000 8.995000 8.363000 Au 7.500000 6.005000 8.363000 Au 20.633000 7.500000 9.226000 Au 20.632000 6.005000 6.637000 Au 20.632000 ... (4 Replies)
Discussion started by: ezitoc
4 Replies

7. Shell Programming and Scripting

Extract fields

Hi, I have a tmp file like below: <ADATA> ANUM=900 ADESC=Saving ATYP=0 TXREGD=0 </ADATA> <ADATA> ANUM=890 ADESC=Saving ATYP=0 ABAL=9000 TXREGD=1 </ADATA> <ADATA> (2 Replies)
Discussion started by: kunigirib
2 Replies

8. Shell Programming and Scripting

Matching fields of rows and then operating

Hi All, I was seaching for script for solaris 5.10 environmet to get a output file from Input file like this. INPUT FILE---------------- 1000KE,MINE,74748 1000KE,YOUR,123998 200KE,MINE,886049 50KE,MINE,474176 50KE,YOUR,379998 100KE,YOUR,999994 50KE,MINE,9601 50KE,YOUR,990393... (3 Replies)
Discussion started by: ashis.tewari
3 Replies

9. Shell Programming and Scripting

Extract duplicate fields in rows

I have a input file with formating: 6000000901 ;36200103 ;h3a01f496 ; 2000123605 ;36218982 ;heefa1328 ; 2000273132 ;36246985 ;h08c5cb71 ; 2000041207 ;36246985 ;heef75497 ; Each fields is seperated by semi-comma. Sometime, the second files is... (6 Replies)
Discussion started by: anhtt
6 Replies

10. Shell Programming and Scripting

Extract fields from from this

thank youuuu (0 Replies)
Discussion started by: rnallamothu
0 Replies
Login or Register to Ask a Question