![]() |
|
|
|
|
|||||||
| 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 |
| Accessing Shell Variables in awk or sed | nasersh | Shell Programming and Scripting | 3 | 05-05-2008 04:44 AM |
| shell variables and sed substitution | duderonomy | UNIX for Advanced & Expert Users | 2 | 05-04-2008 11:54 PM |
| variables in shell | viko | Shell Programming and Scripting | 2 | 03-03-2008 08:09 PM |
| Shell Script Variables | ragha81 | Shell Programming and Scripting | 3 | 08-22-2006 12:43 AM |
| bash shell variables | xNYx | UNIX for Dummies Questions & Answers | 3 | 04-15-2002 01:36 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using shell variables In awk
Oh its not my day for syntax...
Code:
cat gzipsize.txt | awk '{print "echo",$1,$2} > master.txt
Every example of this has led me down a merry road and I'm wondering if anyone can actually explain this finer point to me? let's say there is a previous var=filecontent |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I have found that the server I'm operating on has some anomolies in its implementation of UNIX so if I could possibly ask a favour of someone out there with awk skills...
would it be possible to write a small piece of example code 'which works' where a similar variable is imported and used in an awk function? i ask this because I have every feeling that once again this code will work on every other unix installation and not the one we have here... if so I need to sort it out with the sys admin asap but without some real working code as an example I won't have a chance of explaining. So could anyone possibly run a working example past me? possibly var=varname echo 10 12 | awk 'BEGIN {VAR=var}{print "something",$1,$2,$VAR}' or something similar? |
|
#3
|
|||
|
|||
|
I think you want this:
Code:
var="hello"
var2="myname"
echo $var2 | awk -v variable=${var} '{ print variable,$1}'
hello myname your code shoule be echo 10 12 | awk -v VAR=${var} '{print "something",$1,$2,VAR}' Output: something 10 12 hello |
|
#4
|
|||
|
|||
|
thanks vish, its as I feared then and once again I find I've wasted a day because our beloved server is set up wrong...
my output from your code is var=”hello”: command not found var=”myname”: command not found var2: undefined variable and the output from your improvement on my line is var: undefined variable So I've sat here another full day trying to get things to work because our sys admin has rocks in his head... very sad and frustrating indeed. thanks a million for that snippet of code, without which I couldn't properly explain the anomoly to the tech support and sys admins - so greatly appreciated. i think i need to go to bed now. |
|
#5
|
|||
|
|||
|
what shell are you using? Most of the examples you got used /usr/bin/sh or /usr/bin/bash or /usr/bin/ksh.
Please show output from: Code:
usr/bin/echo "$SHELL" usr/bin/echo "$0" |
|
#6
|
||||
|
||||
|
these are csh/tcsh responses
Quote:
|
|
#7
|
|||
|
|||
|
I've had my brother in law look at this - its based around a university assignment... there are some basic stuff being fooled with like not being able to set variables
var="troy" but i can put them in a text file and make them variables with a cat into the variable anyway we've experimented and it appears the shell has been limited for some reason... in ksh var="troy" has no problem so sorry for the bother everyone - this one seems to be something I need to take back to the lecturers. I've found ways to get around the limitations of what's going on but the time factor is killing me from the business end... had to knock back a good contract yesterday. thanks for the help, it was crucial to my understanding and invaluable to my being able to successfully get past the hurdles. no doubt i will have more questions on the weekend |
|||
| Google The UNIX and Linux Forums |