Hi ,
I have have file which has following structure
01aaaa88888000-9999
01ssss77777000-0991
01ssss7777700000991
02ssss7777700000991
The record 01 is corrupt as value from 12th field to 19th should be positive or start with - however it is 000-9999 it should be -0009999
i need to change the position of - to 12th field and add 0 in place of -
i will not touch 01 records which do not have - sign
Plz guide with approach
Thanks
vino
April 16, 2010, 9:43am
2
You can use the following sed statement
sed -e "s/^\(...........\)\([^-]*\)-\(.*\)/\1-\2\3/g" input.txt
There are 11 dots in buffer 1 [surrounded by \( \)] which represent any 11 characters. The other two buffers contain the rest of the data without the - in them.
Instead of 11 dots, you can have
^\(.\{11\}\)
as well
Thanks a ton actually record length is 300 characters and error characters
0000-9999 is from 180th to 189th
plz guide in that scenario
I don't think sed supports the {##} suffix, but perl does. Here's an (untested) adaptation of the above:
perl -n -e 's/^(.{180})([^-]*)-(.*)$/$1-$2$3/' input.txt
js.
vino
April 19, 2010, 1:14am
5
I have posted
sed -e "s/^\(...........\)\([^-]*\)-\(.*\)/\1-\2\3/g" input.txt
and
^\(.\{11\}\)
Do use the above two and create the sed statement you require.