![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing argument to a pl/sql block | er_ashu | Shell Programming and Scripting | 2 | 05-02-2008 11:42 AM |
| Passing more than one argument in a function | jisha | Shell Programming and Scripting | 1 | 04-23-2008 06:05 AM |
| Argument passing using for or while loop | jisha | Shell Programming and Scripting | 4 | 04-09-2008 12:21 AM |
| Problem with Argument Passing | A_Rod | Shell Programming and Scripting | 4 | 09-13-2006 11:47 AM |
| Passing argument from one script to other | lloydnwo | Shell Programming and Scripting | 3 | 10-27-2005 02:06 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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}'
}
|
|
||||
|
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 04: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 05:29 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|