[linux-lvm] hmmm, curious...
Holger Grothe
grothe at mathematik.tu-darmstadt.de
Fri Feb 1 14:31:02 UTC 2002
On Thu, Jan 31, 2002 at 09:11:13AM +0800, Colin Coe wrote:
>
> Hi all, I have come accross a strange problem while doing some scripting
> with lvdisplay. When I use lvdisplay piped to awk in the first example
> (noting that I have 'hard-wired' one field in awk), a second line is printed
> containing all hard-wired strings, including tabs. But if I encase the
> lvdisplay in backticks and use echo then piped to awk the problem does not
> exist.
>
The whole "problem" is no problem and has absolutely nothing to do with lvm.
It's simply shell programming.
> [root at linux-lvm bin]# lvdisplay -c /dev/rootvg/bbs | awk -F: '{print $1
> "\t\t" $9 "\t" $9 "\t" "2" "\t" $4 }'
> /dev/rootvg/bbs 16 16 2 1
> 2
>
Works as designed :-). The output of lvdisplay -c <logvol> has two
lines. One line with the informations and one empty line. The empty
line contains no fourth or nineth field ==> Only "fixed" things are
printed for the second line. (awk is primarily a line orientated tool).
> [root at linux-lvm bin]# echo `lvdisplay -c /dev/rootvg/bbs` | awk -F: '{print
> $1 "\t\t" $9 "\t" $9 "\t" "2" "\t" $4 }'
> /dev/rootvg/bbs 16 16 2 1
>
Assuming you are using bash (from man bash):
`command`
Bash performs the expansion by executing command and
replacing the command substitution with the standard out
put of the command, with any trailing newlines deleted.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So, it's a feature of the shell.
> I have tried using sed to strip out newline characters, but this has not
> helped. lvdisplay -c /dev/rootvg/bbs | awk -F: '{print $1 "\t\t" $9 "\t" $9
> "\t" "2" "\t" $4 }' | sed "s/\n/ /g"
>
> I have a work around so it is not a major issue, but I thought I'd raise it
> anyway.
>
If you wanna use only the first line of lvdisplay just use only the first
line, e.g. use head in pipe.
lvdisplay -c <logvol>| head -1| awk ...
Holger
--
Holger Grothe (Email: grothe at mathematik.tu-darmstadt.de)
Fachbereich Mathematik, TU Darmstadt
More information about the linux-lvm
mailing list