Convert lowercase to upper case based on certain conditions

Hello Unix Gurus :

It would be really great if a solution can be found

Following is the condition on Solaris

Change all the records to upper case
ignore the case for records having "A2B2 " in them .

how can i use nawk or any other command

Following is the SAMPLE

INPUT FILE (DATA.DAT)

222222 1 A1B1 aaabbb ccccccccc
333333 6 A2B2 XXXXXXXYYYYYY DDDDDDDDDDDDDD
555555 Q222 hhhvvvv jkjkjkjkjk
888888 4 A2B2 jjjjjjjjjjj uuuuuuuuuuuuuu

OUTPUT DESIRED

222222 1 A1B1 AAABBB CCCCCCCCC
333333 6 A2B2 XXXXXXXYYYYYY DDDDDDDDDDDDDD
555555 Q222 HHHVVVV JKJKJKJKJK
888888 4 A2B2 jjjjjjjjjjj uuuuuuuuuuuuuu

Is there any other option to get the above mentioned output

Thanks
B-

Try :

nawk ' { print ($3=="A2B2" ? $0 : toupper($0) }' inputfile 

Jean-Pierre.

Hi,

Using 'perl':

$ cat script.pl
use warnings;
use strict;

while ( <> ) {
        $_ = uc unless index( $_, "A2B2" ) > -1;
        print;
}
$ perl script.pl infile
... output ...

Regards,
Birei

its spitting out an error out
nawk: syntax error at soorce line 1

Always count left and right brackets:

nawk ' { print ($3=="A2B2" ? $0 : toupper($0) ) }' inputfile
sed '/A2B2/!y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' DATA.DAT

Thank you all ! It served my purpose !