Hi, to everybody
i have a string which Looks like this
FT47;3;1;1;;;1;09.02.2017 21:21:19;2;2
and i would like to change to value on one Position only
e.g. the values on Position 6 should change to 1 nevertheyless which values was there before
AIX 4.3.2.0 and csh
i try alread awk but without success and with sed it also does not works ,
i do not have the r Option with mz sed command
thanks in advance
If I understand you:
awk '{ $6=1 } 1' FS=";" OFS=";" inputfile > outputfile
1 Like
I bet it's the second field (position 6 currently with the value of 3)
1 Like
The substitution needs the field to end with the semicolon delimiter.
Not true for the last field.
A simple relief is
sed '
s/$/;/
s/[^;]*;/1;/6
s/;$//
' file
awk is the better tool to work with csv-style fields.
1 Like
Thanks to everybody for your fast Response on my question ,
the solution from Corona688 work perfect only i have to Change field from 6 to 2 as vgersh99 mention and than it work wonderful as request
Wish all of you great Weekend
1 Like
Hi
i had a question for the solution Corona668 has posted, BTW it works perfect. what is the reason / function of the red "1" in the code
awk '{ $2=5 } 1' FS=";" OFS=";" inputfile > outputfile
Thanks for your help
It's the geek version of {print}
.
In fact it gives a non-zero =true value in an implicit if where the default action is {print}
.
1 Like
A code block followed by an expression like that, prints the line whenever the expression is true. As an expression, 1 is always true.
The code block is actually optional. Just awk '1' filename
will print every line... awk '/string/' filename
will match every line matching "string" (where the regex evaluates true), etc. It's a useful on-off switch for printing.
1 Like
Note that since an assignment returns the value assigned and since the value being assigned is not an empty string and is not zero, the script can be written as just a condition with the default action simplifying the script to just:
awk -F';' '$2=5' OFS=';' inputfile > outputfile
1 Like
Thanks a lot to everybody
for your fast Response and a Explanation for my question
With Kind regards