Hi All,
Iam uesing the following bash scrip to filter all the files that have “-62” in their filename, (filter part of the script is ok). when I run script I get a file named “matched_1sp.md5” [(1) of script] which only have 1 space bitween md5sum (32 characters) and the relative path and file name. This is not a valid md5 file because there should be 2 spaces bitween md5sum (32 characters) and the relative path and file name.
I manage to “fix” the problem in a round about way [(2) of script], I want to know is there a better way
fix this problem.
my script:
Code:
#! /bin/bash
#
# Filter files by file name/partial file name. (0.60v)
#
# Read md5sum file "applist.md5" line by line to string "LINE_READ"
# and see if "LOOKFOR" (partial string match) and write all the matched
# lines to an output file.
LOOKFOR="-62" # what to look for is within ""
while read LINE_READ
do
if [[ "$LINE_READ" =~ "$LOOKFOR" ]]
then # matched
# (1) I am writting content of string "LINE_READ" to a file, note
# there is only one space bitween md5 chsum (32 characters) and start
# of relative path abd filename. There should be 2 spaces for it to
# be a proper MD5 sum file.
echo $LINE_READ >> matched_1sp.md5 # write md5 + relative path + filename
# (2) Since above (1) do not work I have to "cut" string LINE_READ to 2 strings,
# CHKSUM=(first 32 characters of string LINE_READ).
# PARTH_AND_FILE=(from 34 character/ possition till the end of the string).
CHKSUM="$(echo $LINE_READ | cut --bytes=1-32)"
PARTH_AND_FILE="$(echo $LINE_READ | cut --bytes=34-)"
# I combine the 2 strings after echo separated by 2 spaces, note the ""
echo "$CHKSUM $PARTH_AND_FILE" >> matched_2sp.md5 # write md5 + relative path + filename
# ^ ^^ ^
# else # did not match
fi
done < applist.md5
My sample md5sum file: (applist.md5)
Code:
c32dc6f04ff02b371129dd4aa923c16b ./packages/ap/streamripper-1.64.6-i486-62.1.txz
78997e57b09985132b91cf506bc8f2da ./packages/ap/a2ps-4.14-i486-3.txz
b41fffae3062fb67118349aea3b0ef3b ./packages/ap/pm-utils-1.2.5-i486-1.txz
840816e056a58fe7c51de7d20b673ce3 ./packages/ap/systemtools-6.2-i486-62.8.tlz
69a7f5efdacde4adac95e92e20bd8e50 ./packages/ap/mc-20090714_git-i486-1.txz
24b27751b834165918876cce90799c0d ./packages/ap/man-1.6f-i486-2.txz
b3b4233f0f08020a0b6195426762e0d4 ./packages/ap/gutenprint-5.2.4-i486-62.1.txz
2ef0f7502bb23f09255950adcdcf52e2 ./packages/ap/cdrkit-1.1.9-i486-62.2.txz
c329ae7f3b9ffa7d085a7922dc5a44d3 ./packages/ap/dmapi-2.2.10-i486-1.txz
44dfa989d9db78d13c5361306e3a8614 ./packages/ap/hdparm-9.27-i486-64.1.tlz
9bb2bdd8eb58b9e2455587ee78a3a049 ./packages/ap/depfinder-0.9.2-i486-62.1.tlz
70ac2d99fb8cecf8c7d41a370760a26d ./packages/ap/netpkg-4.6-i486-62.1.tgz
8ff831361dc6351b3e727fe3ce6e63a1 ./packages/ap/lsscsi-0.22-i486-1.txz
d5025a3b04cc5d7e2431418e72596e82 ./packages/ap/vim-7.2.245-i486-1.txz
fc9c5cd0729f8bbfc5c29bb2726a93d3 ./packages/ap/foomatic-filters-4.0_20090310-i486-60.1.tgz
25d9ab458c4b2ce5698f9e1447261641 ./packages/ap/ntfs-3g-2009.4.4-i486-62.1.tgz
d403019b5a8c6f85c981ab1cb7aeeeeb ./packages/ap/xfsdump-3.0.1-i486-1.txz
dbb7b3374e75e7e51d27a0eff3db540a ./packages/ap/netpkg-4.5.6-i486-60.2.tgz
ae2a3c12a55f0d919adbd70827f41924 ./packages/ap/sudo-1.7.2p1-i486-62.1.txz
bash info
$ bash --version
GNU bash, version 3.1.17(2)-release (i486-slackware-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
Thank you for your time.