![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing argument to a pl/sql block | er_ashu | Shell Programming and Scripting | 2 | 05-02-2008 08:42 AM |
| Passing more than one argument in a function | jisha | Shell Programming and Scripting | 1 | 04-23-2008 03:05 AM |
| Argument passing using for or while loop | jisha | Shell Programming and Scripting | 4 | 04-08-2008 09:21 PM |
| Problem with Argument Passing | A_Rod | Shell Programming and Scripting | 4 | 09-13-2006 08:47 AM |
| Passing argument from one script to other | lloydnwo | Shell Programming and Scripting | 3 | 10-27-2005 11:06 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
passing argument into awk
i'm trying to pass a numerical argument with function xyz to print specfic lines of filename, but my 'awk' syntax is incorrect.
ie xyx 3 (prints the 3rd line, separated by ':' of filename) Code:
function xyz() {
arg1=$1
cat filename | awk -F: -v x=$arg1 '{print $x}'
}
|
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
I tried it anyway and i am still receiving Code:
awk: syntax error near line 1 awk: bailing out near line 1 Last edited by prkfriryce; 02-01-2007 at 12:45 PM. |
|
|||
|
Quote:
Code:
$ cat filename
field1:field2:field3
$ function xyz() {
> awk -F: -v x="$1" '{print $x}' filename
> }
$ xyz 3
field3
Code:
awk -F: '{print $x}' x="$1" filename
thanks edit* the second method works! Thanks! Last edited by prkfriryce; 02-01-2007 at 01:29 PM. |
|||
| Google The UNIX and Linux Forums |