Computing.Net > Forums > Unix > Removing blank lines

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Removing blank lines

Reply to Message Icon

Name: Aki
Date: June 11, 2003 at 02:27:25 Pacific
OS: Solaris
CPU/Ram: 320
Comment:

Hi All,
I want to remove blank lines from a file. I want to compare two files without comments. I have tried this,
cut -f1 -d'#' filename > noComments.txt
This saves a file without comments but replaces the commented lines with blank lines. My aim is to perform this action of striping commented lines on two files and then compare them to see if they are duplicates.
Next part of my question is that I have performed 'cksum', 'md5sum' and 'diff' commands to find the exact duplicates in my directory tree. Is there a way to find out simmilar files and not the exact duplicates. I am more interested if there is a command that exists for this purpose but a piece of code is good as well.
Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: tik_ual
Date: June 11, 2003 at 10:23:06 Pacific
Reply:

Q1 & Q2: Remove Blank Line
vi filename (use 'vi' edit the file)
:g/^$/d (type this ex command for delete blank line)
:g/#/d (type this ex command for delete any lines with '#' at the front)

Q3: Diff the directories (not clear from your question)
for i in `find . -print`
do
echo ${i##*/} > directorylist1
done

You will get list from the CURRENT directory from the file 'directorylist1'. Do it in different directories and then 'diff' the result.



0

Response Number 2
Name: FishMonger
Date: June 11, 2003 at 21:45:44 Pacific
Reply:

If you have Perl on your system, here are some commands that will handle your first question. These commands will also create a filename.bak as a backup.

remove blank lines:
perl -ni.bak -e 's/^\s*$//' filename

remove comment lines:
perl -ni.bak -e 's/^#.*$//' filename

remove both comment & blank lines:
perl -ni.bak -e 's/^\s*$//; s/^#.*$//' filename


0

Response Number 3
Name: FishMonger
Date: June 11, 2003 at 21:48:28 Pacific
Reply:

Oops, change the -ni.bak to -pi.bak


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Removing blank lines

Remove blank lines between two line www.computing.net/answers/unix/remove-blank-lines-between-two-line/5208.html

Remove blank lines from file www.computing.net/answers/unix/remove-blank-lines-from-file/3887.html

blank lines and sed www.computing.net/answers/unix/blank-lines-and-sed/8169.html