Blank line in command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Blank line in command output
# 1  
Old 02-14-2011
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".
...
Code:
ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk '{print $5}' > ${DATAFILE}

...

Code:
$ cat  ${DATAFILE}

123456789 (There's a blank line before the numbers)

Please help me get rid of these blank lines.

Thanks in advance.

Last edited by Franklin52; 02-15-2011 at 03:07 AM.. Reason: Please use code tags
# 2  
Old 02-14-2011
Code:
ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk '!/^$/ {print $5}' > ${DATAFILE}

# 3  
Old 02-14-2011
Code:
awk 'NF>0{print $5}' > ${DATAFILE}

# 4  
Old 02-15-2011
Thanks for your suggestions honglus & yinyeumi, but still not working... it's putting a blank line "" before the real output.
# 5  
Old 02-15-2011
Code:
awk 'NF>3{print $5}'

# 6  
Old 02-16-2011
This command worked:
Code:
ssh user1@${server1} /usr/bin/ls -l /tmp/file1 | awk 'NF>3{print $5}' > ${DATAFILE}

Thanks yinyuemi!

ps. what's the difference between
Code:
awk 'NF>0{print $5}'

and
Code:
awk 'NF>3{print $5}'?


Last edited by Franklin52; 02-17-2011 at 04:00 AM..
# 7  
Old 02-16-2011
you can run first
Code:
/usr/bin/ls -l /tmp/file1

then you wil find the first line is not blank line, NF is less then 3.

Y
This User Gave Thanks to yinyuemi For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies

3. Shell Programming and Scripting

sed command is saving output as blank file

Hi, I am working on a script where I am adding adding colors to few of the info in the output. Now , after that is done , I see colour codes in log files which I don't want to see.:mad::mad::mad::mad: So , I tried using sed command in script as below which gives me o/p (new.log) as blank file... (7 Replies)
Discussion started by: Dream4649
7 Replies

4. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

Blank as variable/output when run from command line

When I run this: PDHDURL=`/usr/bin/curl --silent http://www.phdcomics.com/comics.php | /usr/bin/grep -o http://www.phdcomics.com/comics/archive/.*.gif | head -1` echo -e "$PHDURL" It is totally blank. However, when I just run it from the terminal: /usr/bin/curl --silent... (2 Replies)
Discussion started by: killer54291
2 Replies

6. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

7. Shell Programming and Scripting

Replace two blank line with a single blank line

Hi Guys, I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line. Can you guys help me out? Regards, Magesh (9 Replies)
Discussion started by: mac4rfree
9 Replies

8. Shell Programming and Scripting

Need help in sed command (adding a blank line btw each block generated by pattern)

Hello friends, I have a C source code containing sql statements. I use the following sed command to print all the sql blocks in the source code.... sed -n "/exec sql/,/;/p" Sample.cpp The above sed command will print the sql blocks based on the pattern "exec sql" & ";"... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. UNIX for Dummies Questions & Answers

cant find command that returns blank line

This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions. !/bin/sh sed -e 's/*//g' \ #replace * with nothing -e s/ /X/g' \ #replacing empty space with X -e... (2 Replies)
Discussion started by: jeffersno1
2 Replies
Login or Register to Ask a Question