Sponsored Content
Full Discussion: awk with arguments
Top Forums Shell Programming and Scripting awk with arguments Post 302380171 by momo.reina on Monday 14th of December 2009 12:36:09 PM
Old 12-14-2009
Quote:
Originally Posted by aoussenko
Hi
I have a file which looks like this:

$ cat my_file
f1acc: 1398
f1pdb: 495
f1trn: 1288
f1txn: 7326
t1trn: 8241
t1txn: 8292
p080$

I am trying to "egrep" a certain pattern from this file and put a value of a variable in front of each line, for example:

pnum=555
cat my_file | egrep 'pdb|acc' | nawk -v v=$pnum '{print $v FS $1 FS $2}'

I hoped the output would be as follows:
555 f1acc: 1398
555 f1pdb: 495

But the actual output from the above command is

p080$ cat my_file | egrep 'pdb|acc' | nawk -v v=$pnum '{print $v FS $1 FS $2}'
f1acc: f1acc: 1398
f1pdb: f1pdb: 495

Please help. Thanks a lot -A
to print the value of a set variable just use the variable name, no need to add the "$"

Code:
{print v

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print arguments along with spaces using awk

Hi All, file_1.txt contains aaa bbbb hhhh vvvvv mmmmm iiiii What i want is to search for the first coloumn of each line using awk.i.e as below: awk '/aaa/ {printf(<>)}' file_1.txt The print part (<>) should contain all the values(or coloumns ) in the particular line(here it... (8 Replies)
Discussion started by: jisha
8 Replies

2. Shell Programming and Scripting

awk arguments

Having arguments as follows There are totally 210 error codes. I have already grep custom logs as follows checkerr.sh A awk '$1 == 0 || $1 ==1{print $0}' rep1.txt > success.log B awk '$1 == 84 || $1 ==85 || $1==86 {print $0}' rep1.txt > MediaErr.log i need all the other 205 error... (6 Replies)
Discussion started by: karthikn7974
6 Replies

3. Shell Programming and Scripting

How do we pass multiple arguments into awk

How do we pass multiple arguments into awk : name=john age=12 now i have to pass both age and name into awk.. how to do it? like : awk -v var=... (4 Replies)
Discussion started by: abhinav192
4 Replies

4. Shell Programming and Scripting

Pass command line arguments to awk

I am trying to pass max as a sommand line argument when I call awk. Made the modification in the BEGIN but it is not working I'm getting an error as below: awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory) Somehow it... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

Passing arguments to awk

I have an awk script below which I call using for example awk -f ../../A-Scripts/select-model.awk iterations.txt 16x12 10 I want to be able to use it in a different way like this awk -f ../../A-Scripts/select-model.awk iterations.txt nxz=16x12 iter=10 or awk -f... (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

Arguments to awk

I have an awk script where I pass some arguments For example I will call awk in this fashion awk -v anomaly=nAmon/pAnom -v aloc=zmin/ztran/zmax -v modeldepth=modeldepth My problem is that I want to have the option to pass the variable anomaly in two ways. Either using -v... (10 Replies)
Discussion started by: kristinu
10 Replies

7. Shell Programming and Scripting

awk with arguments

Hi guys, I work in ksh and have a file in the following format: T 18:30 10 23:00 ts1632back W 18:30 10 23:00 ts1632back M 19:30 0 0 tschkback_px1632 T 19:30 0 0 tschkback_px1632 I am using the following 'awk' command to substitute field/colomn 2 across the file if field/colomn 5 is set to... (6 Replies)
Discussion started by: aoussenko
6 Replies

8. Shell Programming and Scripting

Using and passing arguments to shuf within awk

Hello all, I would like to output a random number within a range for every line using awk and shuf. I think I'm almost there, but I don't know how to pass arguments to shuf within my awk script: Input 1 12190 12227 1 12595 12721 1 13403 13639 1 14362 14829 1 14970 15038 awk: awk '{... (2 Replies)
Discussion started by: DerSeb
2 Replies

9. Shell Programming and Scripting

Need to pass shell arguments into Nawk/awk

Hi, I am in critical need of help, Thanks a ton for your help. I need to know how to pass the shell argument into nawk code in AIX. so that my file gets passed into that awk script and it can execute it part. To be detail, i have more than 100 files and in those files a particular field... (6 Replies)
Discussion started by: Selva_2507
6 Replies

10. Shell Programming and Scripting

awk command line arguments not taking

# more minusf.awk #!/bin/awk -f BEGIN { FS=":"; } { if ( $2 == "" ) { print $1 ": no password!"; } } # ./minusf.awk aa aa aa aa awk: can't open aa (6 Replies)
Discussion started by: sri.phani
6 Replies
ZIPGREP(1L)															       ZIPGREP(1L)

NAME
zipgrep - search files in a ZIP archive for lines matching a pattern SYNOPSIS
zipgrep [egrep_options] pattern file[.zip] [file(s) ...] [-x xfile(s) ...] DESCRIPTION
zipgrep will search files within a ZIP archive for lines matching the given string or pattern. zipgrep is a shell script and requires egrep(1) and unzip(1L) to function. Its output is identical to that of egrep(1). ARGUMENTS
pattern The pattern to be located within a ZIP archive. Any string or regular expression accepted by egrep(1) may be used. file[.zip] Path of the ZIP archive. (Wildcard expressions for the ZIP archive name are not supported.) If the literal filename is not found, the suffix .zip is appended. Note that self-extracting ZIP files are supported, as with any other ZIP archive; just specify the .exe suffix (if any) explicitly. [file(s)] An optional list of archive members to be processed, separated by spaces. If no member files are specified, all members of the ZIP archive are searched. Regular expressions (wildcards) may be used to match multiple members: * matches a sequence of 0 or more characters ? matches exactly 1 character [...] matches any single character found inside the brackets; ranges are specified by a beginning character, a hyphen, and an end- ing character. If an exclamation point or a caret (`!' or `^') follows the left bracket, then the range of characters within the brackets is complemented (that is, anything except the characters inside the brackets is considered a match). (Be sure to quote any character that might otherwise be interpreted or modified by the operating system.) [-x xfile(s)] An optional list of archive members to be excluded from processing. Since wildcard characters match directory separators (`/'), this option may be used to exclude any files that are in subdirectories. For example, ``zipgrep grumpy foo *.[ch] -x */*'' would search for the string ``grumpy'' in all C source files in the main directory of the ``foo'' archive, but none in any subdirectories. Without the -x option, all C source files in all directories within the zipfile would be searched. OPTIONS
All options prior to the ZIP archive filename are passed to egrep(1). SEE ALSO
egrep(1), unzip(1L), zip(1L), funzip(1L), zipcloak(1L), zipinfo(1L), zipnote(1L), zipsplit(1L) URL
The Info-ZIP home page is currently at http://www.info-zip.org/pub/infozip/ or ftp://ftp.info-zip.org/pub/infozip/ . AUTHORS
zipgrep was written by Jean-loup Gailly. Info-ZIP 20 April 2009 ZIPGREP(1L)
All times are GMT -4. The time now is 12:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy