Unfortunately I am trapped because it looks as if the shell variables aren't available within an AWK script.
$LOGCAT becomes $0, which just kicks up the entire line instead of a value.
Looks like I may have sunk my own ship by going with AWK.
So close to being finished, and yet the whole day on this one thing...........who would have thought AWK couldn't do a variable in a variable, yet UNIX can.
I guess the writers of AWK have been my downfall......
once again.... You've been provided A sample way of how to solve your initial sample task. All you need to do it understand the code and adjust it your own requirements and/or awk code.
Can anyone just give a plain answer, if they know how to do this.
I would be more than willing to do the same. My job is at stake here.
If you honestly don't know how to do this, but were just trying to help, then thanks for your advice.
As for me it looks to me like I'm going to have to convert this over to Perl or some other language- its going to be a long night.
and basically all I have to do is figure out how to get the value of a variable inside a variable.
The very simple way to do this is to use the "eval" statement. What does "eval" do?
When the shell evaluates (=executes) a command line it does so in several stages. One stage is to "expand" the variables, meaning: replace the variables name by its content. For instance:
The first step the shell takes is to replace the "$x" with its content. The line after this operation is:
Only then the command is executed. "eval" restarts this process of expanding variables after it has already taken place (and before the execution of commands). For instance, the steps in "slow-motion":
That works the same way with arrays. The reason why you have to escape the "$" by backslashes is to protect them from being interpreted in the first run of the shell interpreter: otherwise the shell would read "$$" (which is a perfect shell variable, containing the PID) followed by "x", which is simply a character.
Coming back to your problem: If you want to get out "13" as result the line to execute is - not within awk, but on the command line or within a shell script:
Suppose you have several values and you want to select one:
At last a remark as the moderator here: you might not be "damned", but you might be left alone and/or receive an infraction if you don't tone down your comments. All the people posting in this thread - especially vgersh99 - have been genuinely and sincerely trying to help you, so you have nothing to complain about.
It might be troublesome for *you* that your job is at stake, as you put it, but it is not our fault that you have a job for which you are lacking the necessary qualifications. We are generally inclined to help you along (like everybody else coming here), but first: we are volunteers, therefore rather "inclined" than "bound by duty" to do so; and second: it is *your* problem not to know something you should know, not *ours* that you might not understand our offerings.
Im trying to search for a single variable in the first field and from that output use awk to extract out the lines that contain a value less than a value stored in another variable. Both the variables are associated with each other.
Any guidance is appreciated.
File that contains the... (6 Replies)
I have the following script, and I want to assign the output ($10 and $5) from awk to N and L:
grdinfo data.grd | awk '{print $10,$5}'| read N L
output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Input:
|Running the Rsync|Sun Oct 16 22:48:01 BST 2016
|End of the Rsync|Sun Oct 16 22:49:54 BST 2016
|Running the Rsync|Sun Oct 16 22:54:01 BST 2016
|End of the Rsync|Sun Oct 16 22:55:45 BST 2016
|Running the Rsync|Sun Oct 16 23:00:02 BST 2016
|End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
i have this variable:
varT="1--2--3--5"
i want to use awk to print field 3 from this variable. i dont want to do the "echo $varT".
but here's my awk code:
awk -v valA="$varT" "BEGIN {print valA}"
this prints the entire line. i feel like i'm so close to getting what i want. i... (4 Replies)
Hi All,
I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Hi all,
Hereby wish to have your advise for below:
Main concept is
I intend to get current directory of my script file.
This script file will be copied to /etc/init.d.
A string in this copy will be replaced with current directory value.
Below is original script file:
... (6 Replies)
Hi all,
Hope someone can help me out here.
I have this BASH script (see below)
My problem lies with the variable path.
The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level.
The... (6 Replies)
Dear All,
we have a command output which looks like :
Total 200 queues in 30000 Kbytes
and we're going to get "200" and "30000" for further process. currently, i'm using :
numA=echo $OUTPUT | awk '{print $2}'
numB=echo $OUTPUT | awk '{print $5}'
my question is : can I use just one... (4 Replies)
Hi all,
I have a variable say var1 (output from somewhere, which I can't change)which store something like this:
echo $var1
name=fred
age=25
address="123 abc"
password=pass1234
how can I make the variable $name, $age, $address and $password contain the info?
I mean do this in a... (1 Reply)
I want to instert Category:XXXXX into the 2. line
something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong:
sed "2i\\${n}Category:$cat\n"
Sample:
Titel Blahh Blahh abllk sdhsd sjdhf
Blahh Blah Blahh
Blahh
Should look like... (2 Replies)