Blank line in command output

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.

ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk '!/^$/ {print $5}' > ${DATAFILE}
awk 'NF>0{print $5}' > ${DATAFILE}

Thanks for your suggestions honglus & yinyeumi, but still not working... it's putting a blank line "" before the real output.

awk 'NF>3{print $5}' 

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

ok thanks Y!