Hello.
I'm writing a script where every file you create will generate a md5sum
and store it into a text file.
Say I create 2 files, it'll look like this in the text file:
d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman
d41d8cd98f00b204e9800998ecf8427e /helloworld/test
I want the md5sum
to be cleared from the text file when I delete the file.
So if I delete 'test', the text file will just have:
d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman
I was thinking of using sed
to remove the line, but I'm clueless as to how I'm supposed to define the string (consisting of both the md5sum
and filename).
Is there a better way to remove the line or a way around using sed?
prvnrk
July 23, 2014, 4:21am
2
$ cat text.file
d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman
d41d8cd98f00b204e9800998ecf8427e /helloworld/test
$ rm /helloworld/test
$ grep -v "/helloworld/test" text.file >text1.file
$ mv text1.file text.file
$ cat text.file
d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman
If you want this to done automatically then insert above commands in "your own rm" file [ make sure your PATH goes first to YOUR rm instead of standard UNIX rm ]
1 Like
Thanks for the quick response. It worked
prvnrk:
$ cat text.file
d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman
d41d8cd98f00b204e9800998ecf8427e /helloworld/test
$ rm /helloworld/test
$ grep -v "/helloworld/test" text.file >text1.file
$ mv text1.file text.file
$ cat text.file
d41d8cd98f00b204e9800998ecf8427e /helloworld/saystheman
If you want this to done automatically then insert above commands in "your own rm" file [ make sure your PATH goes first to YOUR rm instead of standard UNIX rm ]
The code needs to be MUCH more complex than this if you're going to create your own rm
utility from end. If you create $HOME/bin/rm
containing:
/bin/rm "$1" && grep -v "$1" /absolute/path/to/text.file >/absolute/path/to/text1.file &&
mv /absolute/path/to/text1.file /absolute/path/ttext.file
then the command sequence:
touch /tmp/world
cd /tmp
rm world
will remove every entry from your sample text.file
.