Searching content of a variable using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching content of a variable using awk
# 8  
Old 09-08-2016
If an external script is creating the contents of the variable TOTALRunning, why confuse all of us with this variable? Why not just pipe the output of that external script to your awk script? (But, we still need to know the format of the output that external script produces and a clear specification of the output you want to produce.)
# 9  
Old 09-08-2016
the content of TOTALRunning looks something like this:

Code:
TOTALRunning='HOST-RESOURCES-MIB::hrSWRunPath.31050 = STRING: "/usr/bin/mod_gearman_worker"
HOST-RESOURCES-MIB::hrSWRunPath.31213 = STRING: "/usr/bin/mod_gearman_worker"
HOST-RESOURCES-MIB::hrSWRunPath.31214 = STRING: "/usr/bin/mod_gearman_worker"
HOST-RESOURCES-MIB::hrSWRunPath.31237 = STRING: "/usr/bin/mod_gearman_worker"
'


Sorry for the inconvenience guys.

The thing is, i have two variables i have to work with. The first is the TOTALRunning, which i have pasted. The combined command i'm looking for searches the TOTALRunning variable and gets a particular number or numbers, based on the amount of lines found containing the content of PROCSEARCH.

Then, it uses the number(s) that were retrieved from the parsing the TOTALRunning variable, to search another variable, which contains this:

Code:
TOTALRunPerfMem='HOST-RESOURCES-MIB::hrSWRunPerfMem.30694 = INTEGER: 3008 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.31213 = INTEGER: 3020 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.31311 = INTEGER: 3020 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.31312 = INTEGER: 3020 KBytes'

the command i use on the second variable this:

Code:
echo "${TOTALRunPerfMem}" | awk '/HOST-RESOURCES-MIB::hrSWRunPerfMem.('${NOIPID}') / && !/No Such Instance currently exists at this OID/ {print $4}'

if all of this can be done combined into one command, that would be great

Last edited by SkySmart; 09-08-2016 at 08:37 AM..
# 10  
Old 09-08-2016
WHY are you making all of us guess WHAT you want, and how? After minutes of reasoning and analysing your posts, I infer you want a list of sort of PIDs from the first variable, separated by an alternation operator for the regex match in the second string, of which you then print a Kbyte count, here 3008 or 3020.
Wouldn't it be easier for all of us if you describe your problem in such a simple manner?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching for variable string

Hi Guys, So im trying to search for the most recent occurance of a string in the most recently updated .log file in a certain directory. The string i am searching for is a value, now if this value is greater than 800 i would like an email sent out with some text (blah blah blah). This is what... (7 Replies)
Discussion started by: hello_world
7 Replies

2. Shell Programming and Scripting

Searching the content of one file using the search key of another file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search key is... (3 Replies)
Discussion started by: csim_mohan
3 Replies

3. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

4. UNIX for Dummies Questions & Answers

searching a variable in environment

all, i am trying to search a variable in unix account. variable TEST_LEVEL=500 , i am getting this value if i grep in env .if i try to see the file where it is defined , i do get 1 file . i commented thsi variable in that file and did relogin, but still i see TEST_LEVEL=500 in thye... (3 Replies)
Discussion started by: deepakiniimt
3 Replies

5. Shell Programming and Scripting

setting a variable by searching within a file

Hi, I am trying to set a variable to be used in later scripting, and am having some difficulty. I want to look in a file called scan.info and find the line that says "variable ok". Then I want to cut the number at the beginning of that line and assign that number as a variable so that later... (4 Replies)
Discussion started by: garth6@hotmail.
4 Replies

6. UNIX for Dummies Questions & Answers

Searching for a string variable

Hi ... I have a string variable STR = "This is a test message" I have a file abc.txt that I am searching for the occurence of the string STR ... I am using the command in a script cat abc.txt | grep $STR It identifies each space as a seperator and prints word by word. How to... (2 Replies)
Discussion started by: mattrix
2 Replies

7. Shell Programming and Scripting

searching content of files in the current and sub directories

Hi I was wondering why command 2 doesn't work like command 1 below. 1. find . -exec grep "test" '{}' \; -print 2. ls -R | grep "test" I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2? Thanks in advance for your help (4 Replies)
Discussion started by: tiger99
4 Replies

8. Shell Programming and Scripting

Content of Content of a variable!

I got a sample BASH script like this : $ cat test MYVAR=$1 DUMMY1="This is tricky" DUMMY2=24 echo $ $ ./test DUMMY1 ./test: line 5: This is tricky: syntax error in expression (error token is "is tricky") **I was expecting the output as "This is tricky", ah! but no luck **But... (2 Replies)
Discussion started by: jaduks
2 Replies

9. UNIX for Dummies Questions & Answers

searching for content of files

Hi, This question may be quite newbish. I've stored a few files on my Unix system and am wondering how to search for their contents (i.e. I input the keyword and get a list of files with this keyword) I'd then like to put it on my website (php). I thought of find and grep, but am not... (19 Replies)
Discussion started by: Aretai
19 Replies

10. Shell Programming and Scripting

Searching and Removing File Content

Hi, I am trying to search a character in a file and remove it from that file.... My file looks something like this: test1.txt ckj12300_00|123|var1|10.2 ckj00200_12|444|var2|11.2 ckj00200_14|4556|var3|33.5 c00200_00_000|4558|var4|33.5 ckj00200_14|4553|var5|33.5... (7 Replies)
Discussion started by: rkumar28
7 Replies
Login or Register to Ask a Question