awk inside functions in bash

awk inside functions in bash

Post by R » Thu, 08 Apr 2004 23:59:11


Hello.

I've got problem with awk inside functions.
Here's an example:

#!/bin/bash
go_awk(){
awk '($1 !~/$1/ {print}' $2
}
file="test"
pattern="qwq"
go_awk $pattern $file

inside go_awk functions $1=$pattern and $2=$file

but $1 is both number of column for awk(first occurence of $1) and $1 is
also a pattern

$1(the patern) is inside ' ' so bash sees only text $1

how can i make my function work with the pattern $1=$pattern?

thanks in advance
best regards R
 
 
 

1. usage of Awk inside awk results....

2. Basic AWK question: set shell vars from inside awk.

Hi all
I am new to awk. Trying to parse "test" from the following input
from inside a shell script.

a=test.val.something
echo $a | awk '{ print substr($1,1,4) }'

The above works fine, but I would like the output (or return
value from awk) in another shell variable.

I tried doing the following.

Trial 1 (did not work):
================
a=test.val.something
b=var
echo $a | awk '{ $'$b' = substr($1,1,4) }'
echo $var,$b

Trial 2 (did not work):
================
a=test.val.something
b=var
echo $a | awk '{ $'$b' = substr($1,1,4) } END { export $'$b'}'
echo $var,$b

Thanks in advance
Sri

3. Re (3): HOW2 call a function from inside awk ?

4. Re (2): HOW2 call a function from inside awk ?

5. HOW2 call a function from inside awk ?

6. Re (2): HOW2 call a function from inside awk ?

7. Using libraries of awk functions from within an executable awk script

8. Setting a variable inside a function and making it global inside an inner function doesn't work?

9. new at "awk.info": fun & games (with awk); the amazing Awk assembler; and more

10. "AWK" or "Awk" or "awk"?

11. new at "awk.info": SQL Awk; embedding Awk in "C"; and more

12. new at "awk.info": fun & games (with awk); the amazing Awk assembler; and more

13. Awk location: #!/bin/awk -f versus #!/usr/bin/awk