| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, I have a text file with lines like those shown below: Power Supply #1 is OK hello Power Supply #1 is Faulty world I have to print like this hello OK -----> the second line and status from first line world Faulty Please help me in this regards. Thanks in advance for the help. Regards, Adarsh. |
|
#2
| |||
| |||
| Adarsh wrote: > Hi, > I have a text file with lines like those shown below: > > Power Supply #1 is OK > hello > Power Supply #1 is Faulty > world > > I have to print like this > hello OK -----> the second line and status from first > line > world Faulty If this is exact and complete data you have various possibilities. One is to select by information whether it is on even or odd line numbers... awk 'NR%2 {s=$NF;next} {print $1,s}' Or you can operate on detected Keywords... awk '/^Power Supply/ {s=$NF;next} {print $1,s}' Or depending on the number of words on the line... awk 'NF>1 {s=$NF;next} {print $1,s}' Janis > > Please help me in this regards. > > Thanks in advance for the help. > > Regards, > Adarsh. |
|
#3
| |||
| |||
| Thanks a lot. I will go ahead with: awk '/^Power Supply/ {s=$NF;next} {print $1,s}' -Adarsh. On Aug 28, 11:54*am, Janis Papanagnou <janis_papanag...@hotmail.com> wrote: > Adarsh wrote: > > Hi, > > I have a text file with lines like those shown below: > > > Power Supply #1 is OK > > hello > > Power Supply #1 is Faulty > > world > > > I have to print like this > > hello *OK * * * * * * *-----> the second line and status from first > > line > > world Faulty > > If this is exact and complete data you have various possibilities. > One is to select by information whether it is on even or odd line > numbers... > > * *awk 'NR%2 {s=$NF;next} {print $1,s}' > > Or you can operate on detected Keywords... > > * *awk '/^Power Supply/ {s=$NF;next} {print $1,s}' > > Or depending on the number of words on the line... > > * *awk 'NF>1 {s=$NF;next} {print $1,s}' > > Janis > > > > > Please help me in this regards. > > > Thanks in advance for the help. > > > Regards, > > Adarsh. > > |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.