C Shell Scripts File Permissions a Simple Spelling Checker Command

C Shell Scripts File Permissions a Simple Spelling Checker Command

Cshell scripts Asimple spelling checker mylatex1.csh #!/bin/csh #!/bin/csh tr -cs "[:alpha:]" "[\n*]" < $1 \ latex file.tex |tr"[:upper:]" "[:lower:]" \ dvips -f file.dvi > file.ps |sort -u > tempfile rm file.aux file.dvi file.log comm -23 tempfile /usr/share/dict/words rm tempfile mylatex2.csh #!/bin/csh Put one word per line \ |convert everything to lowercase \ latex $1.tex |sor t the words,remove duplicates and write the result to ’tempfile’. dvips -f $1.dvi > $1.ps rm $1.aux $1.dvi $1.log Pr int those words in ’tempfile’ that are not in the dictionary. Remove the temporar y file. Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology File permissions Command substitution in a script ls -l To include the output from one command within the command line for another command, enclose the command whose output is to be included rwxrwx rwx within ‘backquotes‘. For example: rwxr -xr -x #!/bin/csh 111101101 echo Date and time is: date echo 1111 011 012 = 7558 echo "Your username is:" ‘whoami‘ echo "Your current directory is:" ‘pwd‘ chmod 755 file.sh chmod u+x file.sh chmod -R a+rX . Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology Editing several files at once (1) sed scripts Suppose wewant to change ‘‘cie’’to‘‘cei’’inall files in the current grep href publications.html \ director y whose name ends with ‘‘.tex’’. |sed ’s/[ˆ"]*"//’ \ |sed ’s/".*//’ #!/bin/csh Instead of giving a single editing command on the command line,wecan ls *.tex | sed ’s/.*/sed s\/cie\/cei\/g & > &tmp/’ > s1 create a script file containing a sequence of editing commands. ls *.tex | sed ’s/.*/mv &tmp &/’ > s2 csh s1 pubs.sed csh s2 s/[ˆ"]*"// rm s1 s2 s/".*// This script creates twoauxiliar y scr ipts: s1 and s2. We can nowrequest that sed applies the the commands in this script file: unix> grep href publications.html | sed -f pubs.sed The command ‘‘csh’’for ks anon-interactiveCshell process that interprets the commands in a script. Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology Editing several files at once (2) get_pdb_stats Suppose there are three files in the current wor king director y whose #!/bin/csh names end with ‘‘.tex’’: ‘‘1.tex’’, ‘‘2.tex’’and ‘‘3.tex’’. #Select lines of StatReport.html containing tabular data, #|replace all HTML tags by a space character, store result in ’temp’. # Scr ipt s1 #Store Year-Deposited pairs (columns 1 and 2) in ’Deposited’. sed s/cie/cei/g 1.tex > 1.textmp #Store Year-Released pairs (columns 1 and 3) in ’Released’. sed s/cie/cei/g 2.tex > 2.textmp #Remove the temporary file. sed s/cie/cei/g 3.tex > 3.textmp grep ’align=right’ /chalmers/users/kemp/DAT160/practical2/StatReport.html \ |sed ’s/<[ˆ>]*>/ /g’ > temp Scr ipt s2 awk ’{print $1, $2}’ temp > Deposited mv 1.textmp 1.tex awk ’{print $1, $3}’ temp > Released mv 2.textmp 2.tex rm temp mv 3.textmp 3.tex Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology Plotting PDB sizewith GNUPLOT awk unix> gnuplot GNUPLOT (Authors: Alfred Aho,Peter Weinberger,Brian Ker nighan) Unix version 3.7 patchlevel 1 last modified Fri Oct 22 18:00:00 BST 1999 awk "{print $2, $1, $3}" pdb.dat Copyright(C) 1986 - 1993, 1998, 1999 Thomas Williams, Colin Kelley and many others awk ’{printf("First is %d, third is %d\n", $1, $3)}’ pdb.dat Type ‘help‘ to access the on-line reference manual awk ’{printf("First is %d, second is %s\n", $1, $2)}’ pdb.dat The gnuplot FAQ is available from <http://www.ucc.ie/gnuplot/gnuplot-faq.html> awk ’{printf("Sum is %d\n", $1+$3)}’ pdb.dat Send comments and requests for help to <[email protected]> Send bugs, suggestions and mods to <[email protected]> wc * | awk ’{printf("%f %s\n", $3/$1, $4)}’ Terminal type set to ’x11’ wc * | awk ’{print $3/$1, $4}’ gnuplot> plot "Deposited" with lines gnuplot> plot "Released" with lines gnuplot> plot "Deposited" with lines, "Released" with lines gnuplot> exit unix> Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology Controlling interactive programs from within scripts fold and nl The interactiveemail program‘‘mailx’’takes input from standard input. To send the contents of ‘‘file’’to‘‘kemp’’, wecan use the following command on the command line or within a script: mailx kemp < file Alter natively,wecan include the text of a message within a script: #!/bin/csh mailx kemp << END This is a test message. END or : #!/bin/csh mailx $1 << END Dear $1, This is a test message. END Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us