Re: [SLUG] bash script - add new line breaks to a text file

From: Ian C. Blenke (ian@blenke.com)
Date: Tue Nov 08 2005 - 13:27:17 EST


Mike Branda wrote:

>Hey all,
>
>I have a problem here with a lot of duplicate files from multiple users.
>Ran a program/script over the weekend that compares MD5's over a
>directory or set of directories called dupliFinder. Works great but it
>doesn't space out the output very well. There are no new lines in
>between the duplicates which makes it very hard to read. Here's a
>sample:
>
>fffe47d32b00c91c2674648582989d87 /file_dir1/file1
>fffe47d32b00c91c2674648582989d87 /file_dir2/files/file1
>fffd46194ed4cc561a3cd6d05328d314 /filedir3/file2
>fffd46194ed4cc561a3cd6d05328d314 /filedir3/filedir4/file2
>fffce49e57d1acae0d9bdbac3acec17c /filedir3/why_do_people_do_this/file4
>fffce49e57d1acae0d9bdbac3acec17c /filedir4/files/this_is_silly/file4a
>fff91d487cee906371a78077b117965d /filedir5/file6_renamed
>fff91d487cee906371a78077b117965d /filedir5/old_files/file6
>fff91d487cee906371a78077b117965d /filedir5/file6
>fff91d487cee906371a78077b117965d /filedir5/innerdir/oldfile/file6
>fff8e5a2e87f6b1a35b594fb309e2c56 /filedir6/file7
>fff8e5a2e87f6b1a35b594fb309e2c56 /filedir6/my_files/file7
>
>I was wondering if anybody has a bash suggestion for reading the 32 char
>MD5 or the first 32 chars on the line and comparing it to the next line
>and if they aren't the same, insert a new blank line in between them.
>
>
Something like this:

    $ cat dupliFinder.txt | ( last=""; while read line; do hash=`echo
$line | awk '{print $1}'`; if [ "$hash" != "$last" ]; then echo ""; fi;
echo $line ; last=$hash; done)

That does it.

 - Ian C. Blenke <ian@blenke.com> http://ian.blenke.com/

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:53:13 EDT