Operating System - HP-UX
1825775 Members
2133 Online
109687 Solutions
New Discussion

setting ORS gives different output

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

setting ORS gives different output

Hi All,

I am executing these command.

bash-2.02# lvdisplay -v /dev/vg00/lvol3 | awk '/Distribution/,/Logical extents/ {print $1}' | grep '/dev/dsk' | cut -f 4 -d "/" | awk '{print $0}'
c2t0d0

bash-2.02# lvdisplay -v /dev/vg00/lvol3 | awk '/Distribution/,/Logical extents/ {print $1}' | grep '/dev/dsk' | cut -f 4 -d "/" | awk 'ORS=" " ; {print $0
}'
c2t0d0 c2t0d0 bash-2.02#


As you can see when i set ORS it displays the same output twice.

Why it is so?

Thanks in advance.
Prasad
3 REPLIES 3
Peter Godron
Honored Contributor
Solution

Re: setting ORS gives different output

Prasad,
try removing the ';' after your ORS.
To prove this try replacing your last awk step with:
awk 'ORS=" "' it will still print c2t0d0
Arunvijai_4
Honored Contributor

Re: setting ORS gives different output

Hi Prasad,

Try this, # lvdisplay -v /dev/vg00/lvol3 | awk '/Distribution/,/Logical extents/ {print $1}' | grep '/dev/dsk' | cut -f 4 -d "/" | awk 'ORS="" ; {print $0}'

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Prasad Joshi
Regular Advisor

Re: setting ORS gives different output

Thanks Peter,
After removing the ; it worked.

Basically the problem was,
The rule has been mached 2 times so, it printed 2 times.

After setting the ORS field with BEGIN it worked very well

bash-2.02# lvdisplay -v /dev/vg00/lvol3 | awk '/Distribution/,/Logical extents/ {print $1}' | grep '/dev/dsk' | cut -f 4 -d "/" | awk 'BEGIN {ORS= " "}; {
print $0}'
c2t0d0 bash-2.02#

Thanks again,
Prasad