LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-26-2009, 05:06 PM   #1
djeikyb
Member
 
Registered: Nov 2005
Location: California
Distribution: ubuntu 10
Posts: 162

Rep: Reputation: 33
Grepping and testing for comments


I'm trying to have my script read through a file and run function foo on lines that don't start with a "#". So for a file containing:
Code:
# vegetables
squash:squash
tomato:tomatoes

# fruit
apple:apples
papaya:papaya
and a script:
Code:
  1 #!/bin/bash
  2
  3 amount=$1
  4 measure=$2
  5
  6 while read line
  7 do
  8         a=`echo "$line" | egrep "^#"`
  9         #echo $a
 10         if [ -z $a ]; then null=
 11         else echo $a; fi
 12 done < ./ingredients
I get output:
Code:
./sample-measure-conversion: line 10: [: #: binary operator expected
# vegetables
./sample-measure-conversion: line 10: [: #: binary operator expected
# fruit
Any ideas what's up?
 
Old 01-26-2009, 05:20 PM   #2
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Try to put quotes in line 10,like this;
Code:
10         if [ -z "$a" ]; then null=

Last edited by alan_ri; 01-26-2009 at 05:22 PM.
 
Old 01-26-2009, 06:48 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
deleted

Last edited by norobro; 01-26-2009 at 07:52 PM. Reason: misread first line in OP
 
Old 01-27-2009, 01:21 AM   #4
djeikyb
Member
 
Registered: Nov 2005
Location: California
Distribution: ubuntu 10
Posts: 162

Original Poster
Rep: Reputation: 33
That works, thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grepping lines... visitnag Linux - Newbie 4 06-26-2008 01:22 PM
grepping different lines..... visitnag Linux - Newbie 5 04-12-2008 09:35 AM
grepping "'s and .'s and the such secretlydead Linux - Software 6 11-30-2007 03:49 AM
Advanced Grepping keysorsoze Linux - General 10 04-20-2007 06:00 AM
grepping all manfiles pgrodt Linux - Software 8 12-01-2006 10:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration