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 1

Status
Not open for further replies.

dabomb

Technical User
Jul 5, 2001
3
0
0
US
To all that gave me help on the previous question concerning deleting and joining in awk.... thank you.
However, I asked the question wrong.... so please indulge me.

Given this input file:

650 432 1139
(PUBLIC ( NAME DIRECT_CONNECT) $)
(PRIVATE ( NAME DIRECT_CONNECT) $)$
$

650 432 1140
(PUBLIC ( NAME KATHY_REYNOLDS) $)
(PRIVATE ( NAME KATHY_REYNOLDS) $)$
$

650 432 1141
(PUBLIC ( NAME BRETT_GEIST) (NONUNIQUE ) $)
(PRIVATE ( NAME BRETT_GEIST) (NONUNIQUE ) $)$
$

650 432 1142
(PUBLIC ( NAME S_KONITZER) $)
(PRIVATE ( NAME S_KONITZER) $)$
$

650 432 1143
(PUBLIC ( NAME MTRO_MDF) $)
(PRIVATE ( NAME MTRO_MDF) $)$
$

650 432 1144
(PUBLIC ( NAME FELIX_CRUZ) $)
(PRIVATE ( NAME FELIX_CRUZ) $)$
$

650 432 1145
(PUBLIC ( NAME VRU_PILOT) $)
(PRIVATE ( NAME VRU_PILOT) $)$
$


I want to get the output file to look like this:

650 432 1145 VRU PILOT
650 432 1144 FELIX CRUZ
etc...

Any ideas would be appreciated...

 
Hi dabomb,

Here is latest for your needs.


nawk '{

if ($0~/^[0-9]+/) {
line = $1" "$2" "$3
getline
}

if ($0~/PUBLIC/) getline

if ($0~/PRIVATE/) {
split ($4,arr,"[_|)]")
printf ("%s %s %s\n", line, arr[1], arr[2] )
}

if ($0~/\ +\$$/) getline

if ($0~/^$/) getline

}' inputfile > outputfile




flogrr
flogr@yahoo.com

 
another way to do this:
awk ' {
gsub(/\([A-Z]+\(NAME/, "", $0)
gsub(/\).*/, "", $0)
printf "%s" , $0
}'
Not as nice but a little easier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top