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

From: Eben King (eben1@tampabay.rr.com)
Date: Tue Nov 08 2005 - 13:39:13 EST


On Tue, 8 Nov 2005, 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.

Pipe it through (or read it into) something like

while read sum name ; do
 [[ $sum != $lastsum ]] && echo
 echo "$sum $name"
 lastsum=$sum
done

You'll get a spurious blank line at the top, and filenames with multiple
spaces might get mangled.

I hope you're not planning to link together files owned by different users;
that won't work, at least the obvious way didn't work.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
                  "God does not play dice" -- Einstein
          "Not only does God play dice, he sometimes throws
          them where they can't be seen." -- Stephen Hawking

----------------------------------------------------------------------- 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:21 EDT