LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-13-2004, 03:07 PM   #1
john8msu
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
Unhappy problem writing a script


Basically I'm trying to write a script that is going to run a program with some different arguments and collect some data from it. here's what i have so far...

Code:
for (( i = 1; i <= 20; i++ ))      ### Outer for loop ###
 do
     ns lantest.tcl $i 1000 1

     for (( j = $i ; j >= 0; j-- )) ### Inner for loop ###
     do
       grep '^r [0-9]\.[0-9]* $i 0' out | wc -l
       done
 done
The statement: "grep '^r [0-9]\.[0-9]* $i 0' out | wc -l" works if i substitute the actual numbers, but doesnt want to work with the variables. This is my main problem that I need to fix and I would greatly appreciate it if someone could help me.

I could also use some suggestions for how I should go about processing the data. That grep/wc is goin to return a number of lines, but I need to do computation on it. Should I send output to a file or a variable?

I need to have a table with the value $i followed by the value returned from the grep/wc command mulitpied by 1000. I want there to be one line for each value of $i.

Thanks in advance for anyone who can help me out!
 
Old 04-15-2004, 02:34 PM   #2
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
In the grep command the $i isn't expanded to the vaue but is rather passed like it is.
I don't know how to fix it in a shell script.
 
Old 04-15-2004, 03:59 PM   #3
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 31
What happens if you use something other than the single quotes (')? One of these, or a combination of them, might work - or not:

grep ^r\ [0-9]\.[0-9]*\ ${i}\ 0 out | wc -l

grep "^r [0-9]\.[0-9]* ${i} 0" out | wc -l

grep '^r [0-9]\.[0-9]* `echo ${i}` 0' out | wc -l

You could also make a concatenate the search string; like

SEARCHSTRING="^r [0-9]\.[0-9]* "
SEARCHSTRING="`echo $SEARCHSTRING $i` 0"

I think
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with writing a script jedimastermopar Linux - General 10 05-02-2005 01:34 PM
help writing script willinusf Programming 7 07-20-2004 11:37 AM
Need help writing a script wswartz Linux - Software 3 04-28-2004 03:35 PM
Writing a Script Nyc0n Linux - General 2 05-27-2002 07:21 PM
writing a Script spanky5125 Linux - Security 5 01-08-2002 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:15 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