Passing shell variable to NAWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing shell variable to NAWK
# 1  
Old 04-23-2008
Passing shell variable to NAWK

I am trying to make a simple script in which i take input from shell and then forward the value to
nawk (BEGIN).

but when i run below mention script so it give no output.

Code:
echo "Enter TRUNK GROUP:"
read TGR

cat /omp-data/logs/5etr/080422.APX | nawk -F"|" -v P=$TGR '

BEGIN {

TG=P;

printf ("DATE IN ST EN  TGN ISEIZE ISATMP   IANS OATMPT   OVFL OSEIZE OSATMP   OANS TOTUSG OOSMTCE   OOS DBLSZR NTWCONG\n");
}



But when i run below code , so its work fine.


Code:
#echo "Enter TRUNK GROUP:"
#read TGR
#cat /omp-data/logs/5etr/080422.APX | nawk -F"|" -v P=$TGR '

cat /omp-data/logs/5etr/080422.APX | nawk'

BEGIN {

TG=700;

printf ("DATE IN ST EN  TGN ISEIZE ISATMP   IANS OATMPT   OVFL OSEIZE OSATMP   OANS TOTUSG OOSMTCE   OOS DBLSZR NTWCONG\n");
}



Can someone help me, to run the above code.
Plz Help
Regards
# 2  
Old 04-23-2008
Double post questions is not allowed, please read the:

https://www.unix.com/unix-dummies-que...om-forums.html

This is a similar question of your previous thread, if you have more questions about your problem, continue here:

https://www.unix.com/shell-programmin...ng-v-vars.html

Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing Shell Variable to awk

Hello All, May i please why my shell variable is not getting passed into awk script. #!/bin/bash -vx i="1EB07C50" /bin/awk -v ID="$i" '/ID/ {match($0,/ID/);print substr($0,RSTART,RLENGTH)}' /var/log/ScriptLogs/keys.13556.txt Thank you. (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

How to pass nawk variable to shell within the same script?

Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it... (4 Replies)
Discussion started by: Optimus81
4 Replies

3. Shell Programming and Scripting

Passing a variable as input to another shell

I have a shell program that calls another shell program the following code works . chkTimeFormat.sh "10/9/12 17:51:19:783."|read c but when I am passing the the time in a variable like in the code below, the shell chkTimeFormat.sh is not returning proper value time="10/9/12... (9 Replies)
Discussion started by: swayam123
9 Replies

4. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

5. Shell Programming and Scripting

Shell to Python variable passing

Hi, I had to create a new thread as the old thread had to much of confusion I have two files shashi.sh and py.py I want to pass a variable from shashi.sh to py.py. How do i achieve that ?. shashi.sh export X=12 echo "$("pwd")" echo "$X" exec python py.py "$(X)" py.py... (0 Replies)
Discussion started by: shashi792
0 Replies

6. Shell Programming and Scripting

Passing the nawk variables to the shell

nawk '($1 ~ "1000") && ($1 ~ "5665" ) { sub ($6,"89");flag =1;print }' old.txt >> new.txt I want to set a flag in awk , if the both conditions are met. I want to pass this flag to shell Can anyone please help me on this (1 Reply)
Discussion started by: prav076
1 Replies

7. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

8. Shell Programming and Scripting

How to make nawk to set a shell variable

Below is the content of the file I am parsing bash-2.03$ cat rakesh cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/gmon.o", errno 28, No space left on device cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/include/README", errno 28, No space left on device... (1 Reply)
Discussion started by: rakeshou
1 Replies

9. UNIX for Dummies Questions & Answers

Passing a for loop variable into nawk

After searching through books and the internet for days I can't seem to find an example of this. I'm trying to pass a variable from a for loop into nawk but can't seem to get all the syntax right. my script (thanks to anbu23 for nawk help) is this: for customers in `cat customers.txt` do... (3 Replies)
Discussion started by: Ant1815
3 Replies

10. Shell Programming and Scripting

passing value to shell variable

dear all How to passing the parameters or results to outside of the AWK program? anyone can help awk '{print $1}' file1 > $a ? (2 Replies)
Discussion started by: trynew
2 Replies
Login or Register to Ask a Question