Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


line combination on AWK

line combination on AWK

line combination on AWK

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..


RE: line combination on AWK


  • /$1 == cell/ - Probably you not want to match the current record against that regular expression
  • You only remember the last seen one of many 1st kind of lines encountered, so when reaching the 2nd kind lines in the bottom half of the file, Awk is able to match them against only one
  • Just pedantry ( and mild speed optimization ), but if a record was just processed as 1st kind of line, then no need to try to process it as 2nd kind too

CODE --> command line

master # awk '/Part/{cell[$2]=$1;next}$1 in cell{print cell[$1],$2}' gab.log
Part=BYN8592P_9NB01_S02 70000
Part=BYN8592P_9NB01_S03 80000
Part=BYN8592P_9NB01_S01 90000 


RE: line combination on AWK

Hi Feherke,

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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close