awk operating with shell vars only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk operating with shell vars only
# 1  
Old 01-26-2009
Question awk operating with shell vars only

Hi all

How do I use awk such that it does not require an input file? I have a situation where I need to process some shell vars within awk (passed into awk with "-v VAR1=$VALUE1, VAR2=$VALUE2" etc), but that processing does not require/use an input file.

Any guidance?

TIA
JG
# 2  
Old 01-26-2009
echo and pipe them into awk maybe. Depending on what you want to do, maybe sed or tr might be more handy.
# 3  
Old 01-26-2009
Code:
awk -v VAR1=$VALUE1 -v VAR2=$VALUE2 'BEGIN { ... do stuff with VAR1/VAR2}' < /dev/null

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Why do awk command line vars behave the way they do?

This came up a little in another thread. Can someone explain some why awk (I happen to use gawk) behaves as follows: $ cat file aaa $ awk 'BEGIN {print x}' x=1 $ awk x=1 'BEGIN {print x}' awk: fatal: cannot open file `BEGIN {print x}' for reading (No such file or directory) $ awk -v... (6 Replies)
Discussion started by: hanson44
6 Replies

2. Shell Programming and Scripting

List of Shell Env Vars

Hia, echo ${!S*} gives me all those env vars starting with S like SHELL SECONDS SHELLOPTS SHLVL etc. is there any way to deflate the shell variables' range like echo ${!A-E*} OR echo ${!A..S*} to list all env vars starting within range of A till E. Thanks Regards, Nasir (1 Reply)
Discussion started by: busyboy
1 Replies

3. Shell Programming and Scripting

operating on string in shell script

i want to read a string and reverse it. hoe do i do that..?? (1 Reply)
Discussion started by: akshaykumar6
1 Replies

4. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

5. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

6. Shell Programming and Scripting

operating on all columns in awk

hi all, i am trying to write an awk script in which i want to perform calculations on each column in a file. i have this so far: total=`awk '/ 1 / { j++ } {sum+=$i} END {print (sum/j)}' "$count".txt` ((count++)) ((i++)) i am calculating the average for every column. i am trying to use... (1 Reply)
Discussion started by: npatwardhan
1 Replies

7. Shell Programming and Scripting

NEW: need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh I want that when somebody enters Trunk Group in variable TGR so it goes into nawk variable TG. echo "Enter TRUNK GROUP:" read TGR cat... (20 Replies)
Discussion started by: wakhan
20 Replies

8. Shell Programming and Scripting

AWK -> getting "global" vars

Hello, presently, I'm calling nawk from my main script and have nawk defined in one file. So I call nawk like this nawk -f file input This file defines how to separate mails in /var/mail/$user and show 1 at a time. However, I would also like to do other actions (delete message, forward... (9 Replies)
Discussion started by: petoSVK
9 Replies

9. Shell Programming and Scripting

need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh echo " Input file: \c" read var1 echo " Input: \c" read var2 nawk -F"|" -v x=$1 ' BEGIN $15 ~ /^'$var2'/ {print $2}' var1 {apary=$15; bparty=$23; time=$4;... (3 Replies)
Discussion started by: amon
3 Replies
Login or Register to Ask a Question