Code Comments
Programming Forum and web based access to our favorite programming groups.Hi All, I have just entered into the shell script world. And I have required a script which will do the following: I have one data file which is having data of following type: aa1,bb1,cc1,dd1 aa2,bb2,cc2,dd2 aa3,bb3,cc3,dd3 and so on.... now what i want to chage the value of column 2 and 4 to some other value for all the rows... i.e. now the output data file should be: aa1,12,cc1,34 aa2,12,cc2,34 aa3,12,cc3,34 and so on.... Please provide me the script for this...i know we want to use awk for this...but i have never used it... And it is very urgent for me..... Please let me know if somebody required further information.... Thanks in advance.....
Post Follow-up to this messagemonty wrote:
> Hi All,
>
> I have just entered into the shell script world. And I have required a
> script which will do the following:
>
> I have one data file which is having data of following type:
>
> aa1,bb1,cc1,dd1
> aa2,bb2,cc2,dd2
> aa3,bb3,cc3,dd3
>
> and so on....
> now what i want to chage the value of column 2 and 4 to some other
> value for all the rows...
> i.e. now the output data file should be:
>
> aa1,12,cc1,34
> aa2,12,cc2,34
> aa3,12,cc3,34
>
> and so on....
>
> Please provide me the script for this...i know we want to use awk for
> this...but i have never used it...
> And it is very urgent for me.....
>
> Please let me know if somebody required further information....
>
> Thanks in advance.....
>
awk 'BEGIN{FS=OFS=","}{$2=12;$4=34}' file
This was an awk question. If you REALLY have a shell question, post it
to comp.unix.shell.
Ed.
Post Follow-up to this messagemonty wrote:
[...]
> I have one data file which is having data of following type:
>
> aa1,bb1,cc1,dd1
> aa2,bb2,cc2,dd2
> aa3,bb3,cc3,dd3
>
> and so on....
> now what i want to chage the value of column 2 and 4 to some other
> value for all the rows...
> i.e. now the output data file should be:
>
> aa1,12,cc1,34
> aa2,12,cc2,34
> aa3,12,cc3,34
>
> and so on....
[...]
awk '{$2=12;$4=34}1' FS="," infile
Use nawk on Solaris.
Dimitre
Post Follow-up to this messageRadoulov, Dimitre wrote:
> monty wrote:
> [...]
>
> Use nawk on Solaris.ta file should be:
> [...]
>
> awk '{$2=12;$4=34}1' FS="," infile
Sorry:
awk '{$2=12;$4=34}1' FS="," OFS="," infile
Dimitre
Post Follow-up to this messageIn article <46cd8870$0$90273$14726298@news.sunsite.dk>, Radoulov, Dimitre <cichomitiko@gmail.com> wrote: ... >Use nawk on Solaris. ITYM: Use gawk everywhere (*). (*) Unless TAWK is available on your platform.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.