Remove blank lines using cat command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove blank lines using cat command
# 1  
Old 06-22-2014
Remove blank lines using cat command

plz help me to figure it out

how i remove empty or blank files using cat command.

i will be very thankful if u send me this answer...


thanks

Last edited by Scrutinizer; 06-22-2014 at 10:54 AM.. Reason: email address removed
# 2  
Old 06-22-2014
You can remove empty or blank lines with the following command:
Code:
awk NF file > newfile

# 3  
Old 06-23-2014
Quote:
Originally Posted by mushfiks1
how i remove empty or blank files using cat command.
hmm... How can i fly to the moon using an invalidated credit card and a screwdriver?

The short answer is: you can't because the tool you want to use (in this case "cat") isn't designed to do what you want. (Actually "cat" is for conCATenating files.)

The long answer is: you might want to rephrase/rethink your question and get a better answer. But it won't even stop at that. Rethinking your question will put you into a state of mind where the solution will come more easily to you, not only because you will get better answers but because you may find it out yourself. Defining correctly (rigidly and meticulously) the goal is - more often than not - already three quarters of the solution.

There are several tools doing perfectly what you want, Unix is rich in all sorts of text filters: sed, awk, sort, and even the native shell can do what you want. You already got a solution in awk, so here is one in sed:

Code:
sed '/^$/d' /path/to/input > /path/to/output

I hope this helps.

bakunin
# 4  
Old 06-23-2014
Quote:
Originally Posted by bakunin
hmm... How can i fly to the moon using an invalidated credit card and a screwdriver?

The short answer is: you can't because the tool you want to use (in this case "cat") isn't designed to do what you want. (Actually "cat" is for conCATenating files.)

[..]
Actually, GNU cat has enough bloat that it can delete repeated blank lines (cat -s), so it is somewhat surprising that there is no option for the removal of all blank lines.. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove Blank lines in VI

Hi, Which option is used to remove blank lines in VI (AIX). ? Regards, Siva (6 Replies)
Discussion started by: ksgnathan
6 Replies

2. Shell Programming and Scripting

Cat Command on File not printing "Blank" Lines?

Hello All, I have a bash script and in it at some point I call an Expect Script that does some stuff and saves its output in a ".txt" file. Example "/path/to/my/file/Expect_Output.txt" file: notice the 2nd line is empty in the file... Data for Host-1 (192.168.1.110) Checking the... (2 Replies)
Discussion started by: mrm5102
2 Replies

3. UNIX and Linux Applications

remove all blank lines

When I 'vi' my test file I see some blank lines. However once I do :set list to display hidden characters, I see the empty lines literally like this: ^I$ How do I remove them? I cannot find a regex to match them. (3 Replies)
Discussion started by: alexsuv
3 Replies

4. Shell Programming and Scripting

How to remove blank lines

Hi, I am facing a problem related to removing blank lines from a text document. Input Error 17-05-2011 11:01:15 VisualSVN Server 2.1 1001 The following information was included with the event: line3 line4 Error 17-05-2011 11:00:25 VisualSVN Server 2.1 ... (13 Replies)
Discussion started by: mayursingru
13 Replies

5. UNIX for Dummies Questions & Answers

Grep command to remove blank lines

The following grep command grep -v "^$" filename > newfilename does not populate the new file with any data. I see it search the entire input file but the output file never gets filled. Is this not the correct command for what Im looking to do? (2 Replies)
Discussion started by: aispg8
2 Replies

6. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

7. Shell Programming and Scripting

Remove blank lines

I really hope someone can help me with this. I have several php files from a forum that I run, that now for some reason have blank lines after every line. Is there an easy way to make a script that does the following: * If there are consecutive blank lines, delete all of them except one. * If... (9 Replies)
Discussion started by: KidCactus
9 Replies

8. Shell Programming and Scripting

Cat Command and Blank Lines

Hi All, I was testing for blank lines and I want to use the cat command only for groupline in `cat /home/test/group` do if then echo "blank found" fi done I want to check if the current line read is a blank line. I have tested with $groupline="\n" ,... (11 Replies)
Discussion started by: datkan
11 Replies

9. Shell Programming and Scripting

remove blank lines

I have joined 2 files. Join command worked fine. but the result showing extra blank lines. I tried to remove blank spaces by using awk (-- -42 RS= ORS="\n\n" file.txt) and sed (sed '/^ *$/d' file.txt)commands but didn't remove any Any suggestions plz:D 123 tab ....... ......tab .......234... (3 Replies)
Discussion started by: repinementer
3 Replies

10. UNIX for Dummies Questions & Answers

Remove blank lines

¿How can i remove blank lines between all lines in a long text file? Example WrongFile.txt : Line 1 Line 2 Line 3 CorrectFile.txt : Line 1 Line 2 Line 3 Thanks in advance :confused: (4 Replies)
Discussion started by: osymad
4 Replies
Login or Register to Ask a Question