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

delete lines and join 3

Status
Not open for further replies.

dabomb

Technical User
Jul 5, 2001
3
0
0
US
I am new to awk and programming is not my strong suit, especially on a UNIX machine. Hopefully someone out there
can point me in the right direction.
I receive the following output;


650 432 1001
(PUBLIC ( NAME TEST_1) (NONUNIQUE ) $)
(PRIVATE ( NAME TEST_2) (NONUNIQUE ) $)$
$

650 432 1005
(PUBLIC ( NAME PAULA_WILTON) $)
(PRIVATE ( NAME PAULA_WILTON) $)$
$

650 432 1012
(PUBLIC ( NAME VITAL_TRBL) $)
(PRIVATE ( NAME VITAL_TRBL) $)$
$


What I want to do is eliminate the line that has "PUBLIC"
in it and join the remaining two lines into one. I know how to get rid of the blank lines and the "PUBLIC" line but I cant seem to get it to join correctly. I read the first
line and the second line into an array but my array only
picks up the first field of each line. When I the output
file out all I get is one continious line of the first
field of each line.

Any thoughts would be appreciated.


 
here is an idea:

awk ' {
if ($0 !~ /PUBLIC/) {
printf "%s" , $0
}
}'

Very simple-doesn't do any record tracking or fancy printing
just one long string without the public line.
 
Hi dabomb,

Don't know if you wanted a space between to
separate the number from the open parenthesis
but this code concatenates like you described.

nawk '{
while ($0!~/\ +\$$/) {
if ($0~/PUBLIC/) getline
line = line$0
getline
}

if ($0~/\ +\$$/) {
print line
line = ""
getline
}

if ($0~/^$/) getline

}' inputfile > outputfile


Hope this helps you!


flogrr
flogr@yahoo.com

 

dabomb,

also you can try this awk solution:


/PUBLIC/ { next }

/^ / { printf "\n"; next; next }

{ printf "%s", $0 }


Bye!

KP.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top