Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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
doneYou will get list from the CURRENT directory from the file 'directorylist1'. Do it in different directories and then 'diff' the result.

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*$//' filenameremove comment lines:
perl -ni.bak -e 's/^#.*$//' filenameremove both comment & blank lines:
perl -ni.bak -e 's/^\s*$//; s/^#.*$//' filename

![]() |
![]() |
![]() |

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