Steve Scrimpshire Posted January 11, 2005 Report Share Posted January 11, 2005 I thought I'd start a topic to consolidate the knowledge I gain on/from bash (mainly from snippets of code that aru posts): Replace text in files with bash: ~$ cat > foo some text for the text example some few more text ~$ while read lines; do echo "${lines//text/WORDS}"; done < foo some WORDS for the WORDS example some few more WORDS ~$ Renaming files with a space in the name (or "The amazing 'find' command"): find . -type f -regex ".*\ .*" -exec bash -c 'mv "$1" "${1// /_}"' '{}' '{}' \; Converting files from upper case to lower case in a *single* directory: ~$ for file in *; do mv "${file}" "$(echo $file | tr 'A-Z' 'a-z')"; done Recursively: ~$ find ./ -type f -exec bash -c 'f=$(basename "$1"); d=$(dirname "$1"); mv -i "$d/$f" "$d/$(echo $f|tr "A-Z" "a-z")"' {} {} \; More to come as I find them... Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 11, 2005 Author Report Share Posted January 11, 2005 A little 'sed' snippet: ~$ cat > input_file schema.current.name=it_current_username schema.current.passwd=it_current_password ~$ sed 's/\(schema.current.name\)=.*/\1=it_new_name/g; s/\(schema.current.passwd\)=.*/\1=new_passwd/g' input_file schema.current.name=it_new_name schema.current.passwd=new_passwd ~$ Quote Link to comment Share on other sites More sharing options...
aru Posted January 11, 2005 Report Share Posted January 11, 2005 :woops: With your permission I'll post some tricks here too, not today, but I will :D Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 11, 2005 Author Report Share Posted January 11, 2005 (edited) Of course you have permission. DUH. Correct me if I post something wrong, too, because I like to do things 'by the book'....like always quoting variables containing filenames, etc. Edited January 11, 2005 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.