pdtak
February 14, 2011, 8:13pm
1
My script ssh's to another server and gathers information then process them. The problem is that the output of a command has an unwanted "blank lines".
...
ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk '{print $5}' > ${DATAFILE}
...
$ cat ${DATAFILE}
123456789 (There's a blank line before the numbers)
Please help me get rid of these blank lines.
Thanks in advance.
honglus
February 14, 2011, 8:23pm
2
ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk '!/^$/ {print $5}' > ${DATAFILE}
awk 'NF>0{print $5}' > ${DATAFILE}
pdtak
February 15, 2011, 12:09pm
4
Thanks for your suggestions honglus & yinyeumi, but still not working... it's putting a blank line "" before the real output.
pdtak
February 16, 2011, 2:20pm
6
This command worked:
ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk 'NF>3{print $5}' > ${DATAFILE}
Thanks yinyuemi!
ps. what's the difference between
awk 'NF>0{print $5}'
and
awk 'NF>3{print $5}'?
you can run first
/usr/bin/ls -l /tmp/file1
then you wil find the first line is not blank line, NF is less then 3.
Y
1 Like