|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I am parsing a file and getting a line number and reading it into a variable cat abd.tx | grep -n "Stopped" | cut -d ":" -f1 | read linenum Bascially that will give me the line num where the word "stopped" occured. Now I want to find what is that line number or the word never occured. I am trying to write an IF condition after this If the linenum has a value then echo process stopped else echo process has not stopped but when I try to write the usuall syntax if [ -n $linenum ] Then in either case, that is, whether the word occured or not it still evaluates it as not a null value. Under no circumstance it takes it as a null value. So I changed the if to if [ $linenum -gt 0 ] or if [ $linenum -ne 0 ] In both cases it says ARGUMENT expected. Either I don't know what it reads when the word doesnt occur or I dont know how to compare the string. Anything else but -n and -z gives me the argument error. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
I don't get why you need a line number at all. Code:
grep 'Stopped' abd.txt |\
while read whole_rec
do
# play around with the whole record here
done |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Firstly the word can occur has many times as possible. Also I am not interested in the line. I want the linenum. Is the word occured then all information after that line to the end of the file. If it didnt occur then then entire file.
Thanks for your quick response though Last edited by kaushys; 07-01-2008 at 05:39 PM.. |
|
#4
|
|||
|
|||
|
I think you want Code:
if [ -z $linenum ] to test whether nothing has been written to the variable. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| NULL checking | Ananthdoss | Shell Programming and Scripting | 6 | 10-11-2011 10:06 AM |
| Checking an array for NULL in C++ | mind@work | Programming | 3 | 08-02-2011 03:33 PM |
| Checking for null value | ganapathi.t | Shell Programming and Scripting | 4 | 04-21-2009 09:37 AM |
| How to compare null and space using single if condition | jayakumarrt | UNIX for Dummies Questions & Answers | 3 | 05-16-2008 05:13 AM |
| How can find Null value in If condition | koti_rama | Shell Programming and Scripting | 2 | 07-17-2007 05:20 AM |
|
|