Operating System - HP-UX
1828428 Members
3733 Online
109977 Solutions
New Discussion

Shell script to check lines?

 
lpuname
Occasional Contributor

Shell script to check lines?

Can someone help to transform the below logic into a shell script, might be easy for some of you.

I have a file with below text, I need if the line has the ":" and the above to it is not a blank line should print " : is incorrect format"

Apple:
vitamin = A
Banana:
vitamin = A

Orange:
vitamin = C

So, If I run the script on above file, it should say Banana: is not a correct format
3 REPLIES 3
Hein van den Heuvel
Honored Contributor

Re: Shell script to check lines?

This works for me:


awk '/:/ && stuff {print $0 "" Bad Format""} {stuff = NF}' test.txt

Cheers,
Hein
Fred Martin_1
Valued Contributor

Re: Shell script to check lines?

It does work on the above data file but I tried it with this data:

Apple: vitamin = A
Banana: vitamin = A

Orange: vitamin = C
Tangerine: vitamin = C

It reports both Banana and Tangerine as having bad format.

As written it is good as a pass/fail test but if you're trying to collect a list of all the errors it may need to be amended.

Just FYI.
fmartin@applicatorssales.com
Fred Martin_1
Valued Contributor

Re: Shell script to check lines?

Sorry, copy and paster error, in my test the data was formatted correctly as the author had shown.
fmartin@applicatorssales.com