Re: Some shell scripts; a more elegant approach?
At 17:59 16.05.2006, Atom Powers wrote: It is difficult to understand exactly what you want your script to do without comments. You may get a better response if you can describe what you want your scripts to do. Thanks man, your advice was really helpful! This though: -- for file in `find -s . -type f -name *.txt`; do # This removes CRLF, double or more empty lines # as well as trailing whitespace. # tr -d '\r' $file | cat -s | sed -E -e 's/[[:space:]]+$//' $file.tmp # Creates file blank containing an empty line # echo blank # Add an empty line to the end of $file.tmp # echo $file.tmp # $file now starts with an empty line too # cat blank $file.tmp $file rm -f blank $file.tmp done for file in `find . -type f -name *.txt -size -300c`; do echo $file: Corrupt done -- I'd like to incorporate the 2nd for loop into the first somehow. That last find command finds files that are below 300 bytes. Now I'm sure there's a better way of doing that. Thanks Atom Powers! :) Take care, Kyrre ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Some shell scripts; a more elegant approach?
Hello! I have a bash script here to clean .txt files. But I want to incorporate a feature where, if the .txt file is less than 300 bytes, it will echo $file: Corrupt. I'm very new to scripting, but I know that this method is not really nice: -- for file in `find -s . -type f -name *.txt`; do mv -f $file $file.tmp tr -d '\r' $file | cat -s | sed -E -e 's/[[:space:]]+$//' $file.tmp echo blank echo $file.tmp cat blank $file.tmp $file rm -f blank $file.tmp done for file in `find . -type f -name *.txt -size -300c`; do echo $file: Corrupt done -- I also have another script here that I'm wondering some about: -- echo Giving files to user $1, group $2. chown -R $1:$2 * echo Setting files to $3, folders to $4. find -s . -type f -exec chmod $3 '{}' \; find -s . -type d -exec chmod $4 '{}' \; -- It mass sets permissions and ownerships. In it, I have to specify $1, $2, $3 and $4. If I just specify let's say $1 and $2, it will error out because the finds in $3 and $4 aren't given anything. How do I avoid this? Thanks people, I apologize for my ignorance, -- Kyrre ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Some shell scripts; a more elegant approach?
It is difficult to understand exactly what you want your script to do without comments. You may get a better response if you can describe what you want your scripts to do. On 5/16/06, Kyrre Nygard [EMAIL PROTECTED] wrote: Hello! I have a bash script here to clean .txt files. But I want to incorporate a feature where, if the .txt file is less than 300 bytes, it will echo $file: Corrupt. I'm very new to scripting, but I know that this method is not really nice: -- for file in `find -s . -type f -name *.txt`; do This line is redundant, if you | $file.tmp below. (or if you turn noclobber off for your shell) mv -f $file $file.tmp tr -d '\r' $file | cat -s | sed -E -e 's/[[:space:]]+$//' $file.tmp I don't see why you need an empty file here. echo blank This line doesn't do anything. echo $file.tmp why not just mv $file.tmp $file? cat blank $file.tmp $file rm -f blank $file.tmp done You should probably do this on the .tmp file before you overwrite the original. for file in `find . -type f -name *.txt -size -300c`; do echo $file: Corrupt done -- I also have another script here that I'm wondering some about: -- echo Giving files to user $1, group $2. chown -R $1:$2 * if [ $3 -a $4 ] ; then echo Setting files to $3, folders to $4. find -s . -type f -exec chmod $3 '{}' \; find -s . -type d -exec chmod $4 '{}' \; fi -- It mass sets permissions and ownerships. In it, I have to specify $1, $2, $3 and $4. If I just specify let's say $1 and $2, it will error out because the finds in $3 and $4 aren't given anything. How do I avoid this? Thanks people, I apologize for my ignorance, -- Kyrre ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- -- Perfection is just a word I use occasionally with mustard. --Atom Powers-- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]