extra space issue with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extra space issue with awk
# 1  
Old 09-03-2010
extra space issue with awk

Code:
for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/|awk '/'$diskname'/ { print ; exit }'
done

No output is returning from the loop.
I think awk put an extra space to the command - lquerypv -h /dev/
so that the command is executed as i.e. lquerypv -h /dev/ hdisk230 with a space between /dev/ and hdisk230.

Please advise how to remove an extra space in this case if my guess is correct.

Thank you
# 2  
Old 09-03-2010
Do:
Code:
lspv |awk '{print "="$1"="}'

so you don't have to guess Smilie
# 3  
Old 09-03-2010
Code:
lspv |awk '{print "="$1"="}'

returns the outputs with =
Code:
=hdisk0=
=hdisk1=
=hdisk113=
...

Code:
 lspv |awk '{print "/dev/"$1}'

gives me like this:
Code:
/dev/hdisk0
/dev/hdisk1
/dev/hdisk113
...

It looks good so far, but if I put in

Code:
for diskname in $(lspv |awk '{print "/dev/"$1}')
do
lquerypv -h |awk '/'$diskname'/ { print ; exit }'
done

I am getting errors:

Code:
 Syntax Error The source line is 1.
 The error context is
                //dev/hdisk0/ >>>  { <<< 
 awk: 0602-500 Quitting The source line is 1.
 Syntax Error The source line is 1.
 The error context is
                //dev/hdisk1/ >>>  { <<< 
 awk: 0602-500 Quitting The source line is 1.
 Syntax Error The source line is 1.
 The error context is
                //dev/hdisk113/ >>>  { <<< 
 awk: 0602-500 Quitting The source line is 1.

Please advise.

Thank you so much

Last edited by Scott; 09-03-2010 at 05:46 PM.. Reason: Code tags, please...
# 4  
Old 09-03-2010
Try:
Code:
for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/|awk -vx=$diskname '$0~x{ print ; exit }'
done

# 5  
Old 09-03-2010
I tried:
Code:
for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/|awk -vx=$diskname '$0~x{ print ; exit }'
done

but, no output is returned still.
Please advise.
# 6  
Old 09-03-2010
Are you sure this command is giving proper output? (containing disk names?):
Code:
lquerypv -h /dev/

# 7  
Old 09-03-2010
The command has to be:

Code:
lquerypv -h /dev/hdisk#

// please note no space on
Code:
/dev/hdisk#

hdisk# comes from
Code:
 '/'$diskname'/ { print ; exit }'

It looks to me that i.e.
Code:
 lquerypv -h /dev/ hdisk0

(please note a space) is executed.

Please advise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - Removing extra character when setting variable

I have a data file d0 that looks like this: $cat d0 server1 running -n-cv- 8G 3.1% 1435d 15h server2 running -n---- 8G 39% 660d 22h server3 running -n--v- 8G 2.5% 1173d 6h server4 running -n---- 8G 1.1% 1048d 20h... (2 Replies)
Discussion started by: jake0391S
2 Replies

2. Shell Programming and Scripting

Extra Space in output - remove

Hi All I am trying to perform the below operation -count=`cat abc.txt | wc -l` echo$count 5 Head=Start"$DATE"00000"$count"File echo $HEAD START15020300000 5File There is a space coming before 5 which is not needed . How to ignore that . (4 Replies)
Discussion started by: honey26
4 Replies

3. UNIX for Dummies Questions & Answers

#Spool/Query executing with extra space.

Hello, I have a requirement where i have to spool some data to a file. i have achived the desired target but m facing one issue. i have attached the script and the output. i checked the data length in the table but it is only 45 for column 1. can you tell me how to remove these extra... (4 Replies)
Discussion started by: Mohammed_Tabish
4 Replies

4. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

5. Shell Programming and Scripting

[Solved] Howto remove extra space in the file

Hi Gurus, I have a file which contains some special char or space. when using cat -evt I can see the file as following: 0,"0000","abc/def aaa ... (6 Replies)
Discussion started by: ken6503
6 Replies

6. Shell Programming and Scripting

my shell now adds extra space at end of each line!

Hi, Since today, with csh or tcsh, if I do 'ls files* > list', every lines end with an extra space! What happenned? What can I do to go back when there was no extra space? If I change to bash, there's no extra space. Thanks, Patrick ---------- Post updated at 03:19 PM... (1 Reply)
Discussion started by: trogne
1 Replies

7. UNIX for Dummies Questions & Answers

awk for removing special characters and extra commas

Hi, I have a .csv file which as empty lines with comma and some special characters in 3rd column as below. Source data 1,2,3,4,%#,6 ,,,,,, 1,2,3,4,5,6 Target Data 1,2,3,4,5,6I need to remove blank lines and special charcters I am trying to get this using the below awk awk -F","... (2 Replies)
Discussion started by: shruthidwh
2 Replies

8. Shell Programming and Scripting

Awk while-loop printing extra character

Hi, I'm using a while-loop in an awk script. If it matches a regular expression, it prints a line. Unfortunately, each line that is printed in this loop is followed by an extra character, "1". While-statement extracted from my script: getline temp; while (temp ~ /.* x .*/) print temp... (3 Replies)
Discussion started by: redbluefish
3 Replies

9. Shell Programming and Scripting

m4 adds extra space at top of file.

I have used m4 in the past to generate source code where aesthetics and space were of no consequence . Now I am using it to generate script and program templates . So here is an excerpt from my m4 file for producing a generic bash script: dnl `$Id$' define(`START_SCRIPT',`#!/bin/bash... (8 Replies)
Discussion started by: Bubnoff
8 Replies

10. Shell Programming and Scripting

awk system() prints extra 0 -- why?

Here's the command I'm running: # echo "hi" | awk '{etime = system("hostname") ; close("hostname") ; print etime""}' And here's the ouput: server.domain.tld 0 Why in the world is that second line, the one that's just "0", there? Many thanks in advance. (2 Replies)
Discussion started by: treesloth
2 Replies
Login or Register to Ask a Question