LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 01-03-2006, 03:53 PM   #1
hhegab
Member
 
Registered: Apr 2002
Location: IL, USA
Distribution: Fedora 13, Ubuntu 10.04 LTS
Posts: 162

Rep: Reputation: 30
how to make a script


Peace,

I have written the following script which is to make a cycling calculations,

----------------
#! /bin/sh
set_P tb 05 MG 100
run 5 50000

set_P tb 06 MG 160
run 5 50000

set_P tb 07 MG 170
run 5 50000

set_P tb 08 MG 180
run 5 50000

set_P tb 09 MG 190
run 5 50000
.
.
.
.
.
set_P tb 70 MG 750
run 5 50000
--------------------
I know how to make a script which do the work if I have one running varaiable, but as you see here
I have two running variables. The first is called 'tb' and it runs from 05 to 70, say, with
a step of 1. The other is called MG and it runs the same number of steps but with a step of 10.

I know it can be done, would you please help me?

Thanks a lot,

PS.
I read a lot a bout shell scripting and I only found talks about doing one loop only. I have here two as you can see.

hhegab
 
Old 01-03-2006, 05:22 PM   #2
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
Code:
#!/bin/bash

tb=05
mg=100

while [ "$tb" -lt 71 ]; do
set_P tb $tb MG $mg
run 5 50000

tb=$(echo $tb + 1 | bc)
mg=$(echo $mg + 10 | bc)
done
Would this be what youre looking for? Or did I understand incorrectly? (:
 
Old 01-04-2006, 01:40 PM   #3
hhegab
Member
 
Registered: Apr 2002
Location: IL, USA
Distribution: Fedora 13, Ubuntu 10.04 LTS
Posts: 162

Original Poster
Rep: Reputation: 30
this is exactly what I dreamt with. Man, you are a genius!

Thank you very much

hhegab
 
Old 01-04-2006, 01:47 PM   #4
hhegab
Member
 
Registered: Apr 2002
Location: IL, USA
Distribution: Fedora 13, Ubuntu 10.04 LTS
Posts: 162

Original Poster
Rep: Reputation: 30
Another script I need is one which is capable of the following;

I have a code which gives me my results as column of numbers just like the following:
2
3
-8
9
57
5
34
.
.
.
-10

Is it possible to make a script which can take these values and put them in a table forum such that they form a second column, the y column, and get the form:
2 2
4 3
6 -8
8 9
10 57
12 5
14 34
. .
. .
. .
100 -10

the idea is that I want to add the first column, which runs in a controlled pattern (add 2 each step), to the results column so I can have a file with two columns which fits the gnuplot.

I hope I could make it clear
 
Old 01-04-2006, 07:59 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Do you mean you have a program that outputs the first set of data and you want to be able to format it without editing the first program?

you can pipe data from one program to another...

prog1 | prog2

prog1 would spit out the first set of data that would then be piped to prog2 through standard in. You can redirect input from standard in with the $< variable.

Alternatively, you could use the output from prog1 in the argv array like so:

prog2 `prog1`

Hope that answers your question.
 
Old 01-04-2006, 11:41 PM   #6
hhegab
Member
 
Registered: Apr 2002
Location: IL, USA
Distribution: Fedora 13, Ubuntu 10.04 LTS
Posts: 162

Original Poster
Rep: Reputation: 30
Thanks for your answer.
I mean the program I have gives me the first column as an output. this is the colum which stands for the y-axis, say. I want to use these as a second column in a file such that the first column, which stands for the x-axis, is written just beside the column of results, the y-axis column, as in the example, so I can use a two-column file, one I added manully and the other which is generated by my program, to plot them with any drawing program.

hhegab

Last edited by hhegab; 01-04-2006 at 11:44 PM.
 
Old 01-05-2006, 03:16 PM   #7
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
You can do it with awk:

myprog | awk '{s+=2; print s,$1}'
 
Old 01-05-2006, 09:10 PM   #8
hhegab
Member
 
Registered: Apr 2002
Location: IL, USA
Distribution: Fedora 13, Ubuntu 10.04 LTS
Posts: 162

Original Poster
Rep: Reputation: 30
Hi Lasse,

My code produces the results in a format which is not directly a column of data, but I can make that column easily, then i should do the job I mentioned above! Any solutions.

Thanks again all,
 
  


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
can i make a script or program make a phone call? nephish Linux - Software 2 08-15-2005 09:02 PM
make a script! okeyla Programming 7 02-07-2005 06:04 AM
A script to make folders... MadClouds Linux - Newbie 2 11-26-2003 08:39 PM
need help in trying to make a script marsonist Linux - Software 8 10-15-2002 09:23 AM
Anyone know how to make a script that will ... kato678 Programming 4 07-19-2002 05:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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