how to check the variable values is blank


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to check the variable values is blank
# 1  
Old 12-06-2008
Bug how to check the variable values is blank

HI ,
I have to check the values of variable is blank or not.
exm :
###test
test1


var=`cate filename | head -1 | cut -c1-3`
I need to check the first three character of 1st line . if it is blank .then exit or we need to process .

Thanks in advance .
# 2  
Old 12-06-2008
Something like the following should work
Code:
if [[ -z $var ]]
then
      echo "Empty var"
      exit 1
fi

# 3  
Old 12-06-2008
unrelated but I would suggest changing the

Code:
var=`cate filename | head -1 | cut -c1-3`

line to

Code:
var=`head -1 filename| cut -c1-3`

There is no reason to read the entire file when you only need the first line.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. Shell Programming and Scripting

Find a blank field and replace values to NA

Hi All, i have a file like col1 col2 col3 13 24 NA 12 13 14 11 12 13 14 22 NA 18 26 NA in this file if i found "NA" other values in the line are also replace by NA Could you help me! (7 Replies)
Discussion started by: Shenbaga.d
7 Replies

3. Red Hat

How to check values stored in variable?

hey, i have stored values of query like this val_2=$( sqlplus -s rte/rted1@rel75d1 << EOF set heading off select source_id from cvt_istats where istat_id > $val_1; exit EOF ) echo $val_2 now , val_2 has five values displayed like this 1 2 3 4 5 what i have to do is to check the... (1 Reply)
Discussion started by: ramsavi
1 Replies

4. Shell Programming and Scripting

Replace blank values for string using sed

Hi everyone, I was wondering how could from a file where each row is separated by tabulations, the row values where are in blank replace them by a string or value. My file has this form: 26/01/09 13:45:00 0 0 26/01/09 14:00:00 1495.601318 0 26/01/09 14:15:00 1495.601318 0 ... (4 Replies)
Discussion started by: tonet
4 Replies

5. Shell Programming and Scripting

check if return value is blank

Hi, i am trying to get the no of users using nofActUsers=$(echo /usr/sbin/lsof -l | grep "/mast/data/users" ) it will return blank, if the user does nto have permissions to run the script. Now I need to check if the valueis blank i have route to another script else the user has to... (1 Reply)
Discussion started by: Satyak
1 Replies

6. Shell Programming and Scripting

finding field count escaping the blank values

Hi All I have a file.Below are few records of the file. sample.txt CPS,ES,843232910001,ESF81462,W N LINDSAY LTD,01674840629,09-FEB-2009,23-FEB-2009,CDR735,ALL CALLS,01674840629 CPS,ES,843232670001,ESF81462,W N LINDSAY LTD,01674840629,09-FEB-2009,23-FEB-2009,CDR734,ALL... (2 Replies)
Discussion started by: king007
2 Replies

7. Shell Programming and Scripting

[bash] Check if variable is set or blank

Hello guys. In my script, i have the following code: echo "The tarfile contains these directorys" tar -tf file.tar > tarlist.txt cat tarlist | awk -F/ '{print $1 "/" $2}' | nl echo "Enter path of the directory you want to extract or just press enter to extract everything: " read path... (1 Reply)
Discussion started by: noratx
1 Replies

8. Shell Programming and Scripting

how to check weather file is blank or not?

Dear All I want to do following task. Kindly suggest. In my script every hour one file is genarated. say xyz.txt. Now if this file contain some data then i want to do task A and if file is blank then i want to do nothing. Kindly help me to do this. regards jaydeep (5 Replies)
Discussion started by: jaydeep_sadaria
5 Replies

9. UNIX for Dummies Questions & Answers

check for the first character to be blank

I'm having a problem when the first line or first character of a file is blank. I need to get rid of both of them when they occur but don't want to delete the line. Does anyone have any suggestions? (7 Replies)
Discussion started by: anthreedhr
7 Replies
Login or Register to Ask a Question