Hi,
My input file is
41;2;xxxx;yyyyy....
41;2;xxxx;yyyyy....
41;2;xxxx;yyyyy....
..
..
I need to change the second field value from 2 to 1. i.e.,
41;1;xxxx;yyyyy....
41;1;xxxx;yyyyy....
41;1;xxxx;yyyyy....
..
..
Thanks in advance.
Hi,
My input file is
41;2;xxxx;yyyyy....
41;2;xxxx;yyyyy....
41;2;xxxx;yyyyy....
..
..
I need to change the second field value from 2 to 1. i.e.,
41;1;xxxx;yyyyy....
41;1;xxxx;yyyyy....
41;1;xxxx;yyyyy....
..
..
Thanks in advance.
cat file | sed -e "s/;2;/;1;/1"
Please take a note of UUOC ![]()
awk -F";" -v OFS=";" ' { $2="1" ; print } ' file
Thanks a lot.
Both works. First option is simple and we can configure more in second option.
Btw: May I know what is UUOC, that matrixmadhan refering to?
could be done as,
sed -e "s/;2;/;1;/1" file
without a kernel data structure -pipe and a new process cat
UUOC - Useless Use Of Cat. Just got that from Wiki.

Most of the commands strings that I write are long series of pipelines feeding each subsequent command -- and in that is the true power of UNIX. I was attempting to demonstrate to deepawkins that he need not save his data as a file BEFORE the transform.
You young kids today!

UUOC and others of a kind are overrated expressions.
Define "Useless".
In case others have to maintain scripts as well, it can be very usefull to use structures which are maybe not the most efficient. Transparancy and readability are important as well.
Most scripts performs small tasks anyway, so who cares aboout an extra structure or process.
If these things are really an issue you shouldn't use shell script at all, but e.g. make a C program.
However I do agree on this specific example.
Before replying am not offending anybody ![]()
Without that the required task could be done !
Cent percent agreed !
This is to be considered - when sed can have its input from a file why it should read the input from pipe
That would solve really and in turn, these unix utilities are 'c' program by the way
Thanks ![]()