Tuesday, December 26, 2006

Search for a string in a selection of files

How to search for a string in a selection of files (-exec grep ...). find . -exec grep "www.athabasca" '{}' \; -print This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output. If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files. find . -exec grep -q "www.athabasca" '{}' \; -print This command is very important for process a series of files that contain a specific string. You can then process each file appropriately. An example is find all html files with the string "www.athabascau.ca". You can then process the files with a sed script to change those occurrances of "www.athabascau.ca" with "intra.athabascau.ca".

Monday, September 25, 2006

Shell Script to Bounce resin and Apache eligently

bash-2.05b$ more /etc/init.d/webfe #!/bin/sh # Startup script for syndicated services web front end # . /home/syndprod/.profile case "$1" in start) /opt/oracle/Apache/Apache/bin/apachectl start su syndprod -c "/internet/apps/resin/bin/httpd.sh start" ;; stop) /opt/oracle/Apache/Apache/bin/apachectl stop su syndprod -c "/internet/apps/resin/bin/httpd.sh stop" ;; restart) /opt/oracle/Apache/Apache/bin/apachectl restart su syndprod -c "/internet/apps/resin/bin/httpd.sh stop" su syndprod -c "/internet/apps/resin/bin/httpd.sh start" ;; condrestart) ;; *) echo $"Usage: -zsh {start|stop|restart}" exit 1 esac exit 0

Friday, August 18, 2006

Remove Carriage Return from Files

Using AWK To use awk to convert a Windows file to Unix, at the Unix prompt, enter: awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt To convert a Unix file to Windows using awk, at the command line, enter: awk 'sub("$", "\r")' unixfile.txt > winfile.txt On some systems, the version of awk may be old and not include the function sub. If so, try the same command, but with gawk or nawk replacing awk. Using TR You can use tr to remove all carriage returns and Ctrl-z ( ^Z ) characters from a Windows file by entering: tr -d '\15\32' < winfile.txt > unixfile.txt You cannot use tr to convert a document from Unix format to Windows. Using vi In vi, you can remove the carriage return ( ^M ) characters with the following command: :1,$s/^M//g Note: To input the ^M character, press Ctrl-v , then press Enter or return.