LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Removing Characters when outputting to a script (https://www.linuxquestions.org/questions/linux-newbie-8/removing-characters-when-outputting-to-a-script-426896/)

thedarkdestroyer 03-21-2006 07:33 AM

Removing Characters when outputting to a script
 
Hi, i have this script that creates another script which lists all duplicate files and give the user an option to uncomment the line to allow it to remove the files, the script is as follows:

#############################
OUTF=henderson.sh;
echo "#! /bin/sh" > $OUTF;
find "$@" -type f -print0 |
xargs -0 -n1 md5sum |
sort --key=1,32 | uniq -w 32 -d --all-repeated=separate |
sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF;
chmod a+x $OUTF; ls -l $OUTF
#############################

the output looks like this:

#! /bin/sh
#rm \ \ ./.kde/share/fonts/fonts.dir
#rm \ \ ./.kde/share/fonts/overide/fonts.dir


but i need it to remove the \ \ ./. so that the output looks like this:

#! /bin/sh
#rm kde/share/fonts/fonts.dir
#rm kde/share/fonts/overide/fonts.dir

Anyone any ideas?

Thanks

marozsas 03-21-2006 08:52 AM

Strange...I'm not getting theses double back slashes...

Code:

miguel@gold:~/tmp> cat henderson.sh
#! /bin/sh
#rm ./motion-3.2.4/debian/motion.1
#rm ./motion-3.2.4/motion.1

#rm ./cron-4.1-20.src.rpm
#rm ./cron/cron-4.1-20.src.rpm

#rm ./motion-3.2.4/pwc-ioctl.h
#rm ./motion-3.2.4/pwc-ioctl.h-10.0.5


thedarkdestroyer 03-21-2006 08:57 AM

Even odder!! when i run this script on SuSE 9.1 it dosent work at all, im running it on Knoppix 4.0 and it works like i mentioned before, im using the sh shell, im pretty new to Linux/Unix/GNU+Linux..... do the shells in different versions compile differently, i though sh would be the same on Knoppix and SuSE

muha 03-21-2006 03:13 PM

maybe you have this problem (LC_ALL='C') :? ~> http://www.linuxquestions.org/questi...hreadid=327916
Quote:

After setting the environmental variable LC_ALL='C' grep behaves as expected. <SNIP>
use [[:upper:]] and [[:lower:]] in scripts.


All times are GMT -5. The time now is 07:53 AM.