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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join a line to a previous line after finding pattern

Status
Not open for further replies.

trub1

Technical User
Jan 13, 2003
6
US
I got the script working and the join works I want to also print the lines not matching. The end result would be printing all lines while joining only lines that start with a specific pattern (41 spaces in this case). My script only prints the joins at this point

Here is the script

{if ($0~/ /)print pl,$0;pl=$0}

I am using awk to run myprob.awk which contains the above script
 
Try this:
Code:
{if ($0~/                                         /)print pl,$0;pl=$0;next}
{print}

Hope This Help
PH.
 
The latest suggestion gave undesired results.
This is what I am trying to do. My first script does the join but I lose the lines in the output that do not need to be joined. I want to end up with both.

Original File Example

Firmware Revisions ..................... SystemROM (8/28/1998) | VideoROM
(05/21/97)
System ROM ............................ 8/28/1998
Video ROM ............................. 05/21/97

Operating System ....................(+) Microsoft Windows NT Server 4.0
(build 1381) Service Pack 6
(-) Microsoft Windows NT Server 4.0
(build 1381) Service Pack 3
System Configured Primary OS .......... Windows NT 4.0

Resulting file Example

Firmware Revisions ..................... SystemROM (8/28/1998) | VideoROM (05/21/97)
System ROM ............................ 8/28/1998
Video ROM ............................. 05/21/97

Operating System ....................(+) Microsoft Windows NT Server 4.0 (build 1381) Service Pack 6
(-) Microsoft Windows NT Server 4.0 (build 1381) Service Pack 3
System Configured Primary OS .......... Windows NT 4.0
 
Note you will need to cut the examples into something that doesn't wrap to see the result.
 
Sorry for the typo. Try this:
Code:
$0~/                                         /{print pl,$0;pl=$0;next}
{print}


Hope This Help
PH.
 
I am not sure what happened in the newest script change. It looks like it appends the pattern to the next occurance of the pattern. Don't get me wrong I really appreciate any help I can get. Maybe I did not explain what I am trying to accomplish very well
 
Can you post the input and output files with line numbering
so we can understand what you want to do ?

Hope This Help
PH.
 
Maybe

{
if ($0 !~ /^ / && NR>1) print ""
printf $0
}
END{print ""}


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Here is the example with line numbers. Great idea

In file
1.Firmware Revisions ..................... SystemROM (8/28/1998) | VideoROM
2. (05/21/97)
3. System ROM ............................ 8/28/1998
4. Video ROM ............................. 05/21/97
5.
6.Operating System ....................(+) Microsoft Windows NT Server 4.0
7. (build 1381) Service Pack 6
8. (-) Microsoft Windows NT Server 4.0
9. (build 1381) Service Pack 3
A. System Configured Primary OS .......... Windows NT 4.0

Out File
1.Firmware Revisions ..................... SystemROM (8/28/1998) | VideoROM (05/21/97)
3. System ROM ............................ 8/28/1998
4. Video ROM ............................. 05/21/97
5.
6.Operating System ....................(+) Microsoft Windows NT Server 4.0 (build 1381) Service Pack 6
8. (-) Microsoft Windows NT Server 4.0 (build 1381) Service Pack 3
A. System Configured Primary OS .......... Windows NT 4.0
 
Try this:
Code:
NR==1{pl=$0;next}
NF>0 && $0~/^  /{pl=pl""$0;next}
{print pl;pl=$0}
END{print pl}

Hope This Help
PH.
 
Thank you for your help. This works perfectly!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top