bash script

K

kubik

Guest
I don't know if this is the right group to ask this question but i try.
I have to modify a netlist using awk.
I have to use awk many times so i have organized a bash shell script
in which a call awk every time i need. Now i have to pass to this script
some parameters by command line when i call it and then use this
parameters when i call awk. For example

-----
awk ' ------ ' file1 > file2
awk -----
----

I want to pass file1 e file2 by command line
How i can do it in bash shell.
Thanks to all!
 
example:

netmung file1 file2

awk ' -----' "$1" > "$2"


If you don't know how many arguments will exist when
netmung is called, you can use the shift command to
get them one at a time:

awk ' ----- ' "$*"
shift
awk ' ----- ' "$*"
shift
....


$0 = name of program
$1 = first argument
$2 = second argument
....
$9 = ninth argument

NOTE! $10 is *not* the tenth argument!

If you need more than 9 arguments, you must use the shift
command

-Chuck

kubik wrote:
I don't know if this is the right group to ask this question but i try.
I have to modify a netlist using awk.
I have to use awk many times so i have organized a bash shell script
in which a call awk every time i need. Now i have to pass to this script
some parameters by command line when i call it and then use this
parameters when i call awk. For example

-----
awk ' ------ ' file1 > file2
awk -----
----

I want to pass file1 e file2 by command line
How i can do it in bash shell.
Thanks to all!
 
kubik wrote:
On Mon, 09 Aug 2004 13:45:44 -0400, Chuck Harris wrote:


example:

netmung file1 file2

awk ' -----' "$1" > "$2"


If you don't know how many arguments will exist when
netmung is called, you can use the shift command to
get them one at a time:

awk ' ----- ' "$*"
shift
awk ' ----- ' "$*"
shift
...


$0 = name of program
$1 = first argument
$2 = second argument
...
$9 = ninth argument

NOTE! $10 is *not* the tenth argument!

If you need more than 9 arguments, you must use the shift
command

-Chuck

kubik wrote:

I don't know if this is the right group to ask this question but i try.
I have to modify a netlist using awk.
I have to use awk many times so i have organized a bash shell script
in which a call awk every time i need. Now i have to pass to this script
some parameters by command line when i call it and then use this
parameters when i call awk. For example

-----
awk ' ------ ' file1 > file2
awk -----
----

I want to pass file1 e file2 by command line
How i can do it in bash shell.
Thanks to all!



How I can refer to $1 and $2 passed by shell in awk models?
For example if i write
awk '--- $1--- {---} ' -----
$1 is interpreted as the first string of the line and not as the
parameters passed by shell. How i can do it?
Thanks

By putting the double quotes around $1.

eg. awk "$1"

single quotes tell the shell to ignore all enclosed characters,
double quotes tell the shell to ignore all enclosed characters, except
$, `, and \


So, if you use double quotes, like this: "$1", the shell will expand
$1 into the first argument to the shell.

If you use single quotes, like this: '$1', the shell will treat $1
like any other string, and pass it through unchanged, as $1

The back quote (`) tells the shell to execute the command enclosed
and send its stdout to the shell.

echo `ls`

will execute the ls command, and pipe its stdout to the echo command
which will send it to the console, just like typing ls would do.

-Chuck
 

Welcome to EDABoard.com

Sponsor

Back
Top