trying to get a boolean response from sed

I have a file coming in with many columns, but the first character of the the coumn is a record type, if I wanted to get a true/false kind of response as to whether it contains at least one of each type of record how would be best?

sed -e '/01/!d; /02/!d; /03/!d; /04/!d' datafile

returns many rows if any are true, I need it to return if all are true and return false if at least one is missing. :frowning:

Is there an easier way to do this?

Headcheck1=`awk -F"," '$1=="01" {print $1}' datafile will do one line only, am a little frustrated.

help please.

If I do the 1's and 2's I hope you can add the 3's and 4's.

awk '/^01/ {ones++} /^02/ {twos++} END {exit ones && twos}' < file

Been trying with this one:

awk '/^01,/ {ones++} /^02,/ {twos++} END {exit ones && twos}' < testfile.txt

RETCODE=$?
if [ $RETCODE -eq 0 ]
then
	echo "File contains one type 01, 02" 
else
	echo "File not valid"
fi					

with the file looking like:

01,Electronic Mail,ECHO,18052006
02,BLAH,BM0100,BLAH UK LIMITED,
03,CR330164,,,BLAH GROUP,BLAH
04,CR330164,040706773,0489300,00
04,CR330164,040706538,9493500,00
04,CR330164,040655269,0496000,28

But it seems to not be working:

: ./validate.sh
+ awk /^01,/ {ones++} /^02,/ {twos++} END {exit ones && twos}
+ 0< testfile.txt
+ RETCODE=1
+ [ 1 -eq 0 ]
+ echo File not valid
File not valid

Have I got a typo?

there is no typo,

check in your validation with if condition

if you have valid no of ones and twos from the input file

number && number ( where number not = 0 )
the output would always be another number and not 0

this is the if condition you had given,

 RETCODE=$?
if [ $RETCODE -eq 0 ]
then
echo "File contains one type 01, 02"
else
echo "File not valid"
fi

when it exits with valid value and equated with 0 which would be false
and u get "File not Valid"

change as,

RETCODE=$?
if [ $RETCODE -ne 0 ]
then
echo "File contains one type 01, 02"
else
echo "File not valid"
fi

Ah, my blunder. Thank you it is now working as it should. :smiley: