1834571 Members
2811 Online
110069 Solutions
New Discussion

vi/sed/awk quetsion

 
SOLVED
Go to solution
Edgar_10
Frequent Advisor

vi/sed/awk quetsion

Hi,

I have a file containing 5 fields($1-$5) and I want to insert in the beginning of $2 & $3 a "0".Anyone know how best to do this in vi/sed/awk?


Thanks!
6 REPLIES 6
Edgar_10
Frequent Advisor

Re: vi/sed/awk quetsion

Hi,

No worries, sorted issue, I will do following:

cat file| awk '{print $1,"0"$2,"0"$3,$4,$5}'

Thanks!
James Murtagh
Honored Contributor
Solution

Re: vi/sed/awk quetsion

Hi Dean,

Best to keep it simple, just use:

# cat file|awk '{print $1, 0$2, 0$3, $4, $5}' > newfile

Regards,

James.
Francisco J. Soler
Honored Contributor

Re: vi/sed/awk quetsion

Hi,

If the fields $2 and $3 have some pattern that vi can handle you can do it with vi, is quicker than other methods.

On the other hand you can do it with awk like this:

awk '{printf("%s 0%s 0%s %s %s\n", $1,$2,$3,$4,$5)}' file_in > file_out

and rename the file_out to file_in

I assume the separator filed is the space bar.

HTH
Frank.
Linux?. Yes, of course.
Caesar_3
Esteemed Contributor

Re: vi/sed/awk quetsion

Hello!

awk '{print $1, 0$2, 0$3, $4, $5}' >

Caesar
Tim D Fulford
Honored Contributor

Re: vi/sed/awk quetsion

Hi

Al the above replies deserve 10 pts. If you would assign points it would be much appriciated by all who answer questions & contribute to the forums.

Points are what make this forum work & shows the author's sincere appriciation.

Tim

-
John Meissner
Esteemed Contributor

Re: vi/sed/awk quetsion

as stated before...

cat file | awk '{print $1,"0"$2,"0"$3,$4,$5}' > newfile

All paths lead to destiny