LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-01-2008, 01:17 PM   #1
TrumpetMan258
LQ Newbie
 
Registered: Mar 2008
Posts: 1

Rep: Reputation: 0
Using a variable containing a filename in grep


I'm working on a shell script that counts the number of each html tag in a file. Here's the part I'm having trouble with:

Code:
while getopts "df:" param
do
    if test '$param = d'; then
        delim=$OPTARG
    elif test '$param = f';  then
        files=$OPTARG
    fi
done

echo $delim
echo $files

grep -oh '<[a-zA-Z0-9]\+\( [a-zA-Z0-9]\+=".\+"\)*/\?>' $files | tee list.tmp | sort -u  | tee sortlist.tmp | xargs -I% grep -c % list.tmp > numbers.tmp
If, for example, I call "./tagstats -f project2.html", the while loop successfully gets the filename and the "echo $files" successfully prints it out, but when I try to use the files variable in grep, the script just hangs at the command line. In other words, grep doesn't do anything. But if I hard code the filename into the command, it does work. How can I use that files variable in grep?
 
Old 03-01-2008, 01:27 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,988
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Hi,

And welcome to LQ!

And all I can say is your script works for me. Not that it's
results mean much to me. Are you feeding it a strange file-name
by any chance?


Cheers,
Tink
 
Old 03-01-2008, 01:27 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Using ' will prevent $param from being replaced with its value. You need to use " instead.
ta0kira
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
grep from filename.txt can't get the whole line papasj Programming 3 02-25-2008 12:38 PM
Grep result passed to variable cornish Programming 5 11-15-2007 05:05 PM
How to use grep to search for a specific variable.. memo007 Linux - Software 4 02-24-2007 05:52 PM
how to use environment variable as part of filename beeblequix Linux - Newbie 3 07-11-2006 04:55 PM
bash: how to edit cat <filename> | grep <keyword> feature? sirpelidor Linux - Software 2 06-20-2005 02:00 PM


All times are GMT -5. The time now is 02:03 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration