Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Shell Script Required.......
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.....


Report this thread to moderator Post Follow-up to this message
Old Post
monty
08-23-07 11:57 PM


Re: Shell Script Required.......
monty 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
08-23-07 11:57 PM


Re: Shell Script Required.......
monty 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

Report this thread to moderator Post Follow-up to this message
Old Post
Radoulov, Dimitre
08-23-07 11:57 PM


Re: Shell Script Required.......
Radoulov, 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

Report this thread to moderator Post Follow-up to this message
Old Post
Radoulov, Dimitre
08-23-07 11:57 PM


Re: Shell Script Required.......
In 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.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
08-23-07 11:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:09 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.