To find a character immediately following a word

Hello,

I have data in one file like -

UNB+UNOA:1+006415160:1+WF0000010188:ZZ+080701:0600+2++DELFOR++++T'UNH+2+DELFOR:D:97A:UN................

Now, I want to find what is the character immediately following UNB(here +) UNOA (here :slight_smile: or the character immedialtely preceding UNH (here ') & want to store them in different variables.

Please help me on how to do it.


#  sed 's/.*UNB\(.\).*/\1/' infile
+


#  sed 's/.*\(.\)UNH.*/\1/' infile
'

etc...

HTH

I did not get ur solution, Tytalus.

'sed' is used for replacinone str with another. I want to find the first occurance of UNB, UNH or UNOA and store the corresponding characters in different variables. I will use those variables later in the script.

Please guide.