Removing blank lines
|
Original Message
|
Name: Aki
Date: June 11, 2003 at 02:27:25 Pacific
Subject: Removing blank linesOS: SolarisCPU/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.
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: tik_ual
Date: June 11, 2003 at 10:23:06 Pacific
|
Reply: (edit)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.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: FishMonger
Date: June 11, 2003 at 21:45:44 Pacific
|
Reply: (edit)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
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: