trying to get a boolean response from sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to get a boolean response from sed
# 1  
Old 05-26-2006
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. Smilie

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.
# 2  
Old 05-26-2006
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
# 3  
Old 05-30-2006
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?
# 4  
Old 05-30-2006
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,
Code:
 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,

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

# 5  
Old 05-30-2006
Ah, my blunder. Thank you it is now working as it should. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to assign result of boolean expression?

Hello I would to write the test on one line like : declare -i x=0 y=0 ........ some code assign value 0 or 1 to x and y ........ # if either x or y or both is set to 1, then do something if -o ; then do_something fi Any help is welcome (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Dummies Questions & Answers

If statement with two boolean conditions

#!/bin/bash if && then echo "True" else echo "False" fi Hi everyone, I am new to UNIX, here I have a if statement elevating two boolean conditions. I thought the output should be True because there are + in the statement. But it turns out to be False. Can anyone... (3 Replies)
Discussion started by: mryuyu1111
3 Replies

3. Shell Programming and Scripting

Boolean expression

hi, im learning python language. and my teacher gives me this question on class: Boolean expression : not (p or not q) what is the correct answer for that? i still dont understand, and please give me a link for a new beginner in python to learn. thanks (1 Reply)
Discussion started by: jazzyzha
1 Replies

4. Shell Programming and Scripting

'AND' boolean not working !!!!

Dear all, IT seems to be rather small issue, but is not resolved. What Google suggest does no work..! #!/bin/bash date jobNo=$(awk '/Jobs with... (4 Replies)
Discussion started by: emily
4 Replies

5. Shell Programming and Scripting

boolean expression in bash

Can someone, please, help me to make this condition valid/accepted in bash? I really cannot. I'm stuck with the brackets... This one tells me: missing `]' if ]; then # NOTIFY ERROR... fi And... I'd also appreciate a link to bash documents that explain these things. All... (2 Replies)
Discussion started by: mamboknave
2 Replies

6. Homework & Coursework Questions

Boolean expressions for If's

1. The problem statement, all variables and given/known data: Im experimenting with if expressions for an assignment. What i want to do is check if an input of read x y z will be checked against x for 1-999 for y for and for z for 1-999. Am i doing this right? or perhaps you could tell me... (0 Replies)
Discussion started by: Ren_kun
0 Replies

7. UNIX for Advanced & Expert Users

Find Boolean operators help

I was reading this find guide and I saw something with the -and option that I don't think is correct. Do you need the -and option in this? $ find /mp3-collection -name 'Metallica*' -and -size +10000k I found my file that was bigger than 500 MB with and without the -and option. ~ $ find /... (1 Reply)
Discussion started by: cokedude
1 Replies

8. Shell Programming and Scripting

Boolean expression issues

Hi everybody: I'm working on a script to send emails with logs attached based on one single rule..."check if the number of errors has increased since the last time the script ran" Basically what my script does is read from a previous file with the last trace of errors the previous error... (3 Replies)
Discussion started by: hyunkel_01
3 Replies

9. Shell Programming and Scripting

set boolean after comparison

Hi there, Sorry if the title doesn't mean much to you, I don't know how to sum up my pb in one line. I'd like to set a value to 0 or 1 depending on the result of a comparison. Here's what I do: supernova:~# a= supernova:~# isempty=$(] && echo 1 || echo 0) supernova:~# echo $isempty 1... (4 Replies)
Discussion started by: chebarbudo
4 Replies

10. Shell Programming and Scripting

boolean parameter

Hi, I'm calling an oracle procedure from shell script, this procedure has boolean parameter, the default is false, but I need to pass true value to the procedure... how can I do that in shell script , below is my script: ################ Initialise Environment ################# initialise()... (0 Replies)
Discussion started by: aya_r
0 Replies
Login or Register to Ask a Question