I would like to ask if it's possible to have multiple conditions checked while using sed.
Basically I have a text file that can contain strings as follows:
a 0000 0000 AA00 0000
a 000000000 AA00 0000
a 0000 0000 BB00 0000
a 0000 0000 CC00 0000
b 0000 0000 AA00 0000
b 0000X0000 BB00 0000
- If columns 12-13 contain 'AA|CC' and column 6 is empty, then add 'Z' to column 6.
- If columns 12-13 contain 'BB' and column 6 is empty, then add 'ZZ' to column 6.
- This applies only to rows starting with 'a'.
Therefore, output should be:
a 0000Z0000 AA00 0000
a 000000000 AA00 0000
a 0000ZZ0000 BB00 0000
a 0000Z0000 CC00 0000
b 0000 0000 AA00 0000
b 0000X0000 BB00 0000
What I have came up with so far is the following.
sed -E '/^a(.{12})A|C/s/^(.{6})[\t ]/\1ZZ/g'
I think I can eventually do this separately, but I can't figure if it's possible in a one liner and I can't figure it out how to use multiple conditions for double chars.
Any help would be greatly appreciated if possible.