I have a file with the following format:
A 485C72F95C72E15C EXTERNAL
B CC32480A3247F84A SYSTEM
C EC2A63F12A63B76C EXTERNAL
I want to supply the letter in the first column using the value of the variable 'letter', and replace the value in the second column with a value I supply in the variable 'id'. The third column may or may not differ or match in any case. The first and second columns will never contain spaces or special characters.
I've tried to use sed
, but my sed-fu is not strong. I came up with this:
letter=A
id=MYNEWIDSTRING
sed "/$letter /s/[^ ]*/$id/2"
The output is:
A MYNEWIDSTRING EXTERNAL
B MYNEWIDSTRING SYSTEM
C EC2A63F12A63B76C EXTERNAL
The id is replaced in two lines, I'm assuming this is due to 'A ' being matched at the end of the original id string.
I know to use sed -i
to edit the file inplace, but not doing it yet, as my command is still a bit dodgy.
Where have I gone wrong, or should I be using a different method?