Hi,
I'm using ksh, I have a file called testfile.txt with all characters, I would like to check the file, if all are capital letter then it will return 1, if it not all capital letter then return 2.
I know i can use tr to do it, but just can't think of better way to write the script.
Appreciate any advise given.
Thanks in advance.
nawk '{if (gsub(/[^A-Z]/, "")){s++;exit}}END{exit ++s}' myFile;echo $?
1 Like
hi,
Thanks for the suggestion. I can't find nawk command, but i do find awk.
my OS is hpux B.11.31
many thanks
try awk instead
1 Like
Hi,
Thanks again. What about if i want to return 0 for all uppercase else return 1?
nawk '{if (gsub(/[^A-Z]/, "")){s++;exit}}END{exit s}' myFile;echo $?
1 Like
Hi,
What if I my text file (myFile) I have space and numeric, the above will return 1 even no small capital was found, anyway to get over space and numeric and return 0 if all capital letter regardless the file has numeric or space.
Thanks
Try:
awk '/[a-z]/{r=1}END{exit r?r:"0"}' file