Trouble formatting egrep command with AWK


 
Thread Tools Search this Thread
Operating Systems AIX Trouble formatting egrep command with AWK
# 1  
Old 03-22-2006
Trouble formatting egrep command with AWK

Hi,
I'm new to scripting and AIX. I'm running the following:

lspv | awk '{ print "lspv",$1" | egrep 'PP\|PHYSICAL'; lspv -l",$1 }'

Which creates this command:

lspv hdisk0 | egrep PP|PHYSICAL; lspv -l hdisk0
lspv hdisk1 | egrep PP|PHYSICAL; lspv -l hdisk1

Troube is, I need the patterns for egrep to be enclosed in single quotes
lspv hdisk0 | egrep 'PP|PHYSICAL'; lspv -l hdisk0
lspv hdisk1 | egrep 'PP|PHYSICAL'; lspv -l hdisk1

I thought using backslashes would help:
lspv | awk '{ print "lspv",$1" | egrep \'PP\|PHYSICAL\'; lspv -l",$1 }'

but get the same results:
lspv hdisk0 | egrep PP|PHYSICAL; lspv -l hdisk0
lspv hdisk1 | egrep PP|PHYSICAL; lspv -l hdisk1

I've entered the command manualy to get the desired results, below:

root@test:/ > lspv hdisk1 | egrep 'PP|PHYSICAL'; lspv -l hdisk1
PHYSICAL VOLUME: hdisk1 VOLUME GROUP: sanvg
PP SIZE: 16 megabyte(s) LOGICAL VOLUMES: 5
TOTAL PPs: 955 (15280 megabytes) VG DESCRIPTORS: 2
FREE PPs: 534 (8544 megabytes) HOT SPARE: no
USED PPs: 421 (6736 megabytes) MAX REQUEST: 256 kilobytes
hdisk1:
LV NAME LPs PPs DISTRIBUTION MOUNT POINT
sas 52 52 00..52..00..00..00 /sas
worktest 326 326 07..128..191..00..00 /worktest
db2data1 32 32 32..00..00..00..00 /db2data1
loglv00 1 1 00..01..00..00..00 N/A
scripts 10 10 00..10..00..00..00 /scripts


Any ideas?
# 2  
Old 03-22-2006
Code:
lspv | awk -v q="'" '{ print "lspv",$1" | egrep " q "PP\|PHYSICAL" q "; lspv -l",$1 }'

# 3  
Old 03-22-2006
Thanks, vgersh99!
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

Trouble using awk command

Hi, I have 2 .txt pads containing data. I need a script which reads content of one .txt file, performs some operations and calculates a number which is stored in a variable. Now , all the content of another .txt pad should be appended to first .txt pad at pre calculated nth line number. ... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

3. Shell Programming and Scripting

Trouble with awk command

Hi, I need to read a string with ; separated using loop one filed by one field and perform some operation. Can you please check and let me know how to print command parameterised. key=phani;ravi;kiran number_of_keys=`echo $key|awk '{print NF}' FS=';'` for (( i = 1; i <= $number_of_keys;... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

4. Homework & Coursework Questions

having massive trouble with 5 questions about egrep!

Hi all! I need help to do a few things with a .txt file using egrep. 1. I need to list all sequences where the vowel letters 'a, e, i, o, u' occur in that order, possibly separated by characters other than a, e, i, o, u; consisting of one or more complete words, possibly including punctuation. ... (1 Reply)
Discussion started by: dindiqotu
1 Replies

5. Shell Programming and Scripting

Help with egrep command

Hello folks, Here's how my current egrep command works: egrep "NY|DC|LA|VA|MD" state_data.txt I am planning to use a file to enter all allowable state values like say a new state_names.lookup with the following data: NY DC LA VA MD egrep "`cat state_names.lookup`"... (6 Replies)
Discussion started by: calredd
6 Replies

6. Shell Programming and Scripting

Help with egrep command

cat /tmp/inventory.csv|grep AARP|egrep -v "T11|12.4\(7\)" how do i exclude in addition to above 12.4\(3\) I have tried adding this in i.e -v "T11|12.4\(7\)|12.4\(3\)" but it did not work (3 Replies)
Discussion started by: slashbash
3 Replies

7. Shell Programming and Scripting

Trouble with passing Variable from bash to awk gsub command

Would really appreciate it if someone could point out my mistake in this line of code, i've been staring blankly at it trying everything i can think of some time now and coming up with nothing. #!/bin/bash echo "Enter Username" read Username awk -F: -v var=${Username} '/^var:/... (9 Replies)
Discussion started by: Nostyx
9 Replies

8. Shell Programming and Scripting

Formatting problem with cat, egrep and perl

Hi guys I'm using the following script to change input file format to another format. some where I'm getting the error. Could you please let me know if you find out? cat input.txt|egrep -v ‘^#'|\ perl -ane ‘if (@F>3){$_=~/(chr.+):(\d+)\ s()/;print $1,”\t”,$2,”\t”,($2+35),”\n”}'\ > output.bed ... (1 Reply)
Discussion started by: repinementer
1 Replies

9. Shell Programming and Scripting

Help with egrep command

Hi All, I am using egrep command to search one pattern. Following is the command i am using egrep -i "ACL*" filename but its also giving me the records which do not contain ACL. any help would be appreciated. Regards, Sam (3 Replies)
Discussion started by: sam25
3 Replies

10. Shell Programming and Scripting

egrep command

I'd like to grep a pattern of a version number as *_number.number.number number should be digit my grep is |egrep '^*++\.+' It works for V_3.2.1 or V _5.3.2 but not with V_43.6.543 !!!!! How can I specify any repetition of digit in the ? thanks, (4 Replies)
Discussion started by: annelisa
4 Replies
Login or Register to Ask a Question