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

What am I doing wrong? Help 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I'm trying to convert a multilined file to a single line separated by colons and then "chomp" off the last colon..

I got this so far:

Code:
cat tapes_111.txt | grep U0[2-3]'*' | awk '{print $1}' | sort | awk -vORS=':' '{ print }' | sed -e 's/.$//'

but the sed portion isn't working correctly.. with the sed it deleted the entire line.. I just want the trailing colon to be deleted.

example:

U02313
U03029
U02593
U02100
U03023
U02787


Output should look like:

U02100:U02313:U02593:U02787:U03023:U03029



Thanks
 
A starting point:
awk '/^U0[23]/{printf "%s%s",(++i==1?"":":"),$1}END{printf "\n"}' tapes_111.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV... this is the results I got from yours..

# awk '/^U0[23]/{print "%s%s",(++i==1?"":":"),$1}END{printf "\n"}' tapes_111.txt
%s%s U02439
%s%s : U02715
%s%s : U02263
%s%s : U02711
%s%s : U02426
%s%s : U02449
%s%s : U02435
%s%s : U02434
%s%s : U02987
%s%s : U02712
%s%s : U02996
%s%s : U02995
%s%s : U02946
%s%s : U02726
%s%s : U02989
%s%s : U02397
%s%s : U02948
%s%s : U03053
%s%s : U02380
%s%s : U02890
%s%s : U02429
%s%s : U02801
%s%s : U02349
%s%s : U03061
%s%s : U03059
%s%s : U03056
%s%s : U03045
%s%s : U02806
%s%s : U02810
%s%s : U02184
%s%s : U02747
%s%s : U02121
%s%s : U02360
%s%s : U02904
%s%s : U02351
%s%s : U02130
%s%s : U02367
%s%s : U02775
%s%s : U02579
%s%s : U02526
%s%s : U02105
%s%s : U02387


but a combination of mine with the previous mentioned threat worked out... Probably more code and longer than necessary but it works on my HP-UX.


Code:
cat tapes_111.txt | grep U0[2-3]'*' | awk '{print $1}' | sort | awk -vORS=':' '{ print }' | awk '{sub(/.$/,"");print}'
 
Some more condensing...

Code:
cat tapes_111.txt | grep U0[2-3]'*' | awk '{print $1}' | sort | awk -vORS=':' '{sub(/.$/,"");print}'
 
grep U0[2-3]'*' tapes_111.txt| awk -F ":" 'sub(/.$/,""){ print $1 | "sort" }'

... ?

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
You haven't read properly my suggestion:
awk '/^U0[23]/{print[!]f[/!] "%s%s",(++i==1?"":":"),$1}END{printf "\n"}' tapes_111.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Works for me...

bash-3.2# cat awktest
U02313
U03029
U02593
U02100
U03023
U02787


bash-3.2# awk '/^U0[23]/{printf "%s%s",(++i==1?"":":"),$1}END{printf "\n"}' awktest
U02313:U03029:U02593:U02100:U03023:U02787


perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Ack! I should have double-checked that. Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top