Command in inside awk statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command in inside awk statement
# 1  
Old 11-21-2013
Command in inside awk statement

Hello

can you please help me with below script which is meant to delete clients from multiple netbackup policies
I want to run a command insdie awk statement
apparelnlty this script is not working for me

Code:
 
for i in $( cat clients_list) 
do   
bppllist -byclient $i | awk '/^CLASS/{system("bpplclients $2 -delete  $i")}' 
done


Code:
 
cat clients_list
client1
client2
client3
client4
...
...

Many Thanks
Sara
# 2  
Old 11-21-2013
Try:
Code:
... | awk -v i=$i '/^CLASS/{system("bpplclients " $2 " -delete  " i)}'

You should show some output of bppllist -byclient $i, and what bpplclients expects as input, otherwise it's just a guess, really.
# 3  
Old 11-21-2013
this command will list all policies that have client1

Code:
 
bppllist -byclient client1 | awk '/^CLASS/{print $2}'
 
output
 
policy1
policy2
policy3

below command delete client from previous policies
Code:
 
bpplclients policy1 -delete client1
bpplclients policy2 -delete client1
bpplclients policy3 -delete client1

# 4  
Old 11-21-2013
Then it should work. Does it not?
# 5  
Old 11-21-2013
Quote:
Originally Posted by Scott
Then it should work. Does it not?
no it is not working unfortunately L
# 6  
Old 11-21-2013
Could this help ?
Code:
for i in $(cat clients_list) 
do 
	bppllist -byclient client1 | awk '/^CLASS/{print $2}' | while read policy
	do
		bpplclients $policy -delete $i
	done
done

This User Gave Thanks to pravin27 For This Post:
# 7  
Old 11-21-2013
Just saying it isn't working isn't exactly helpful.

If the output of bppllist -byclient client1, 2, 3, 4, etc. is:
Code:
policy1
policy2
policy3
policy4
...

Then the following command (to simulate the next step) gives the shown output:
Code:
for i in $( cat clients_list) 
do   
  echo CLASS policyN $i | awk -v i=$i '/^CLASS/{system("echo bpplclients " $2 " -delete " i)}' 
done

Code:
bpplclients policyN -delete client1
bpplclients policyN -delete client2
bpplclients policyN -delete client3
bpplclients policyN -delete client4

So:
Code:
for i in $( cat clients_list) 
do   
  bppllist -byclient $i | awk -v i=$i '/^CLASS/{system("bpplclients " $2 " -delete " i)}' 
done

should execute:
Code:
bpplclients policy1 -delete client1
bpplclients policy2 -delete client2
bpplclients policy3 -delete client3
bpplclients policy4 -delete client4

This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

awk trouble inside another command

I tried running this. dsh -w server1 'lsof /audit | awk '{ print $2 }'' It did not like above so I tried to escape the single parenthesis at the end. dsh -w server1 'lsof /audit | awk '{ print $2 }\'' It then hung so I changed up the parenthesis to this. This worked. dsh -w server1... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

awk statement piped inside sed

Hello folks, I have multiple occurrences of the pattern: ).: where is any digit, in various text context but the pattern is unique as this regex. And I need to turn this decimal fraction into an integer (corresponding percent value: the range of 0-100). What I'm doing is: cat... (1 Reply)
Discussion started by: roussine
1 Replies

3. UNIX for Beginners Questions & Answers

Using df -g command with awk to get SQL statement

Hi Gurus... good day; currently I trying to run the df -g command with awk to get to convert in SQL statement, but I have some errors; df -g | awk '{print "This is the FileSystem: " $NF, " This is LV: "$1, "This is SIZE: "$2, "This is FREE: " $3, "This is the USED% "$4}' This on AIX... (3 Replies)
Discussion started by: wcastibl
3 Replies

4. Shell Programming and Scripting

Grep command inside awk

Hi, I would like to use grep command inside awk. Here is my requirement below : file.txt col1 col2 col3 col 4 col 5 wrxwrx 124 jun 3 Sensex.EMEA wrxwrx 120 jun 4 Emex.US wrxwrx 130 feb 3 passion.AUS wrxwrx 145 feb 9 lession.AUS wrxwrx 130 feb 5 pass.US wrxwrx 130 feb 8... (5 Replies)
Discussion started by: Balasankar
5 Replies

5. Shell Programming and Scripting

Help in using date command inside awk

Hi All, bash-3.2$ autorep -J BOX_NAME% -l0 | grep BOX_NAME| awk -f awkScript.awk sh: -c: line 0: unexpected EOF while looking for matching `"' sh: -c: line 1: syntax error: unexpected end of file BOX_NAME SU 06/21/2013 03:44:03 06/21/2013 07:46:37 0 #My awkfile { ... (3 Replies)
Discussion started by: ddspark
3 Replies

6. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Shell Programming and Scripting

Sysdate inside awk print statement

Hi, I am using awk statement to extract data from a file and write a new file with certain columns rearranged and few hard coded values added to new file. Now i need to add a column with sysdate. can i do that inside the awk print statement? Now: nawk ' /^3/ BEGIN {FS=","}... (2 Replies)
Discussion started by: selvankj
2 Replies

8. Shell Programming and Scripting

How to use same variable value inside as well as outside of the awk command?

Hi Jim, The following script is in working state. But i m having one more problem with awk cmd. Could you tell me how to use any variable inside awk or how to take any variable value outside awk. My problem is i want to maintain one property file in which i am declaring variable value into that... (12 Replies)
Discussion started by: Ganesh Khandare
12 Replies

9. Shell Programming and Scripting

awk inside another awk statement

hi all, i have two files 1) a.txt one two three 2) abc "one" = 10 pqr "three" = 20 345 "two" = 0 this is what i want in third file (3 Replies)
Discussion started by: shishirkotkar
3 Replies

10. Shell Programming and Scripting

Running command inside awk

Hi, I have a awk script to read a CSV file. After reading the values i want to call a executable (nameely call_it) with the values what i read from the scv file. I dont want to use system command inside the awk. Is there any other way to run the executable from the awk script Thanks ... (1 Reply)
Discussion started by: Raghuram.P
1 Replies
Login or Register to Ask a Question