Visit Our UNIX and Linux User Community


Extracting Tag along with specific lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting Tag along with specific lines
# 1  
Old 06-08-2011
Extracting Tag along with specific lines

I have this input file:
Quote:
TDka1111111>
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B

TDka2222222>
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B

TDka3333333>
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=3,Lenfermpaoa=RU-1-3,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=B
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=5,Lenfermpaoa=RU-1-5,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B_OI
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=A
citernedlo=1,amarau=1,Lenfermpaoa=RU-1-1,excelsheet1=ru,Buckle=B
and the desired output is as follows:
Desired Output
Quote:
TDka1111111>
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
TDka2222222>
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
TDka3333333>
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
This is a sample taken from a huge file. Basically, the script should take the tag (TDK11..1>) add everything that has bukle=A until it sees the blank lines. Then takes the next tag (TDK2222>) adds everything that includes buckle=A and so forth for the entire sheet. Finally remove all the empty lines from the final file.

Danke!

Last edited by Ernst; 06-08-2011 at 01:49 PM..
# 2  
Old 06-08-2011
Please, show what you've tried already and where exactly are you stuck.
# 3  
Old 06-08-2011
I tried the following:
Code:
awk '{print $1, $5, $7}' stl.hi > stl1.hi
grep -v "^=" stl1.hi > stl2.hi

and
Code:
sed '/^$/d' stl2.hi > stl3.hi

Neither works. Not sure how to get the specific of Buckle=A
# 4  
Old 06-08-2011
Code:
nawk -F, '/>/{print;next} NF { if($NF ~ "^Buckle=A[_]*") print $1, "Buckle=A"}' myFile

Not sure if you want to pick up Buckle=A and Buckle_A_OI (based on some of your previous posts).

Last edited by vgersh99; 06-08-2011 at 02:16 PM.. Reason: _ in A_ should be optional
# 5  
Old 06-08-2011
Code:
$ nawk -F, 'NF>1&&/A$/{print$1,$NF}NF==1' infile
TDka1111111>
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
TDka2222222>
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
TDka3333333>
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
citernedlo=1 Buckle=A
$


Previous Thread | Next Thread
Test Your Knowledge in Computers #249
Difficulty: Easy
Senator Albert Gore, Jr. authored the High Performance Computing and Communication Act of 1991, creating what Gore referred to as the information superhighway.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

2. Shell Programming and Scripting

Extracting a string from html tag

Hi I am new to string extractions in shell script... I am trying to extract a string such as #1753 from html tag looks like below. <a class="model-link tl-tr" href="lastSuccessfulBuild/">Last successful build (#1753), 40 min ago</a> and want the value as 1753 Could someone help me to... (3 Replies)
Discussion started by: hicharbo
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting data between specific lines, multiple times

I need help extracting specific lines in a text file. The file looks like this: POSITION TOTAL-FORCE (eV/Angst) ----------------------------------------------------------------------------------- 1.86126 1.86973 1.86972 ... (14 Replies)
Discussion started by: captainalright
14 Replies

4. UNIX for Advanced & Expert Users

Extracting specific lines from data file

Hello, Is there a quick awk one-liner for this extraction?: file1 49389 text55 52211 text66 file2 59302 text1 49389 text2 85939 text3 52211 text4 13948 text5 Desired output 49389 text2 52211 text4 Thanks!! (5 Replies)
Discussion started by: palex
5 Replies

5. UNIX for Dummies Questions & Answers

Filtering data -extracting specific lines

I have a table to data which one of the columns include string of text from within that, I am searching to include few lines but not others for example I want to to include some combination of word address such as (address.| address? |the address | your address) but not (ip address | email... (17 Replies)
Discussion started by: A-V
17 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. Shell Programming and Scripting

extracting specific text from lines

Hello, i've got this output text: and i need it to look something like this: which means that there won't be absolute path of each directory, just it's size and the last word after last '/' in each line, and i also don't need last line '1.7M /tmp' Looks like there is a simple... (5 Replies)
Discussion started by: krater559
5 Replies

8. Shell Programming and Scripting

Extracting the value of an attribute tag from XML

Greetings, I am very new to the UNIX shell scripting and would like to learn. However, I am currently stuck on how to process the below sample of code from an XML file using UNIX comands: <ATTRIBUTE NAME="Memory" VALUE="512MB"/> <ATTRIBUTE NAME="CPU Speed" VALUE="3.0GHz"/> <ATTRIBUTE... (5 Replies)
Discussion started by: JesterMania
5 Replies

9. Shell Programming and Scripting

extracting specific lines from a file

hi all, i searched in unix.com and accquired the following commands for extracting specific lines from a file .. sed -n '16482,16482p' in.sql > out.sql awk 'NR>=10&&NR<=20' in.sql > out.sql.... these commands are working fine if i give the line numbers as such .. but if i pass a... (2 Replies)
Discussion started by: sais
2 Replies

10. Shell Programming and Scripting

Extracting text out of specific lines

Hi, I have a file like LAHORE 2009-04-16 16:04:19 THU S5830 FAULT MESSAGE SUPPRESS STATUS LOC : ASP00 STS : SUPPRESSING CONTINUE INF : F6201 TRUNK. DATA FAULT REPORT COMPLETED LAHORE 2009-04-16 16:04:20 THU S8400 ISUP SIGNALLING TRACE -... (3 Replies)
Discussion started by: krabu
3 Replies

Featured Tech Videos