Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

line combination on AWK 1

Status
Not open for further replies.

l3p15

Vendor
May 7, 2005
11
TH
Dear Expert,

Need your advise where my mistaken.
trying for make combine line with "key" but not working...

if input like this :
Part=BYN8592P_9NB01_S01 Section=9
Part=BYN8592P_9NB01_S02 Section=10
Part=BYN8592P_9NB01_S03 Section=11
Section=10 70000
Section=11 80000
Section=9 90000

and i expect to have result :
Part=BYN8592P_9NB01_S01 90000
Part=BYN8592P_9NB01_S02 70000
Part=BYN8592P_9NB01_S03 80000

i am try using AWK :
awk '/Part/{cell=$2;}/$1 == cell/{print cell,$1,$2}' gab.log

not give me any output..

Thanks alot if u have some clue to do..

//Levi

 
Hi

[ul]
[li][tt]/$1 == cell/[/tt] - Probably you not want to match the current record against that regular expression[/li]
[li]You only remember the last seen one of many 1[sup]st[/sup] kind of lines encountered, so when reaching the 2[sup]nd[/sup] kind lines in the bottom half of the file, Awk is able to match them against only one[/li]
[li]Just pedantry ( and mild speed optimization ), but if a record was just processed as 1[sup]st[/sup] kind of line, then no need to try to process it as 2[sup]nd[/sup] kind too[/li]
[/ul]
Code:
[blue]master #[/blue] awk '[fuchsia]/Part/[/fuchsia][teal]{[/teal]cell[teal][[/teal][navy]$2[/navy][teal]]=[/teal][navy]$1[/navy][teal];[/teal][b]next[/b][teal]}[/teal][navy]$1[/navy] [teal]in[/teal] cell[teal]{[/teal][b]print[/b] cell[teal][[/teal][navy]$1[/navy][teal]],[/teal][navy]$2[/navy][teal]}[/teal]' gab.log
Part=BYN8592P_9NB01_S02 70000
Part=BYN8592P_9NB01_S03 80000
Part=BYN8592P_9NB01_S01 90000


Feherke.
feherke.github.io
 
Hi Feherke,

100% work....
Thanks you...

//Levi...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top