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!

First fields only 1

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
Hey all, I have a file something like this...

1:2:3:4:5:6:7:8

I want to be able to either replace 1 using awk or sed

awk -F ":" '{print "new_value",$2,$3,$4,$5,$6,$7,$8}' where the colons are retained.

new_value:2:3:4:5:6:7:8

Shortcut?

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Hi

Code:
awk -F ":" 'BEGIN{OFS=":"}{$1="new_value"}1' /input/file
[gray]# or[/gray]
sed 's/[^:]*:/new_value:/' /input/file
Tested with [tt]gawk[/tt] and GNU [tt]sed[/tt].

Feherke.
 
What is the "1" behind the curled bracket good for? ta in forward for an answer :)

laters
zaxxon
 
What is the "1" behind the curled bracket good for?
1 always evaluates to true, so always executes the default action (ie print current record).

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top