Maker Pro
Maker Pro

bash script

K

kubik

Jan 1, 1970
0
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
 
C

Chuck Harris

Jan 1, 1970
0
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
 
K

kubik

Jan 1, 1970
0
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

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
 
C

Chuck Harris

Jan 1, 1970
0
kubik said:
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
 
J

Just an Illusion

Jan 1, 1970
0
Hi Kubik,

Chuck said:
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 \

That is not the recommended one.
In fact the rule to give parameter to your awk (gawk/nawk) command
depend of your OS and your version of awk (be carefull, lot of time now
awk is an alias fot gawk)

If you want just use the name of you input file into your awk command
script you can use the predefined parameter FILENAME, like this


awk '--- FILENAME ---{---}' $1

as you can use IFS, OFS, BEGIN, END...

If you want more parameters, look your 'man awk' result and check if
your awk is not GNU awk (gawk)


Regards,
JaI
 
Top