DOC PREVIEW
FSU COP 4342 - More tr Example

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Fall 2006 Shell programming, part 4More tr examplestr ’&’ ’#’ translate ampersands to hashtr -s ’\t’ squeeze consecutive tabs to one tabCOP 4342Fall 2006 Shell programming, part 4More tr examples[langley@sophie 2006-Fall]$ cat /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 localhost.localdomain localhost128.186.120.8 sophie.cs.fsu.edu127.0.0.1 a.as-us.falkag.net127.0.0.1 clk.atdmt.com[langley@sophie 2006-Fall]$ tr -s ’\t’ < /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 localhost.localdomain localhost128.186.120.8 sophie.cs.fsu.edu127.0.0.1 a.as-us.falkag.net127.0.0.1 clk.atdmt.comCOP 4342Fall 2006 Shell programming, part 4More tr examplestr -d ’\015’ delete carriage returns from a DOS fileCOP 4342Fall 2006 Shell programming, part 4basenamebasename lets you remove leading directory strings. Itcan also remove suffixes simply by specifying the suffix asa second argument.[langley@sophie 2006-Fall]$ basename ‘pwd‘2006-Fall[langley@sophie 2006-Fall]$ var1=/etc/inetd.conf[langley@sophie 2006-Fall]$ basename $var1 .confinetdCOP 4342Fall 2006 Shell programming, part 4dirnamedirname does the opposite function of basename: itreturns the leading path components from a directoryname.[langley@sophie 2006-Fall]$ echo ‘pwd‘/mnt-tmp/Lexar/fsucs/cop-4342/2006-Fall[langley@sophie 2006-Fall]$ dirname ‘pwd‘/mnt-tmp/Lexar/fsucs/cop-4342[langley@sophie 2006-Fall]$ dirname 05-shells4.tex.[langley@sophie 2006-Fall]$ dirname ‘pwd‘/xyz/mnt-tmp/Lexar/fsucs/cop-4342/2006-FallCOP 4342Fall 2006 Shell programming, part 4sortFor all of the files listed, sort will sort the concatenatedlines of those files to stdout. The most useful options are-f, which means to fold case, -n to sort numerically ratheralphabetically, -u to remove duplicates (“u” is short for“unique”), and -r to reverse the order of the sort.You can specify particular fields to sort by specifyinga field separator (whitespace is the default) with the -toption, and then using -k to specify particular fie lds.COP 4342Fall 2006 Shell programming, part 4sort examples[langley@sophie 2006-Fall]$ sort /etc/passwdadm:x:3:4:adm:/var/adm:/sbin/nologinamanda:x:33:6:Amanda user:/var/lib/amanda:/bin/bashapache:x:48:48:Apache:/var/www:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologincanna:x:39:39:Canna Service User:/var/lib/canna:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologindesktop:x:80:80:desktop:/var/lib/menu/kde:/sbin/nologinCOP 4342Fall 2006 Shell programming, part 4sort examples[langley@sophie 2006-Fall]$ sort -r /etc/passwdxfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologinwnn:x:49:49:Wnn Input Server:/var/lib/wnn:/sbin/nologinwebalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologinvmail:x:502:502::/home/vmail:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinuser1:x:505:505::/home/user1:/bin/bashtest:x:503:503::/home/test:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncCOP 4342Fall 2006 Shell programming, part 4sort examples[langley@sophie 2006-Fall]$ sort -k3,3n -t: /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinCOP 4342Fall 2006 Shell programming, part 4sort examples[langley@sophie 2006-Fall]$ sort -k4,4n -k3,3n -t: /etc/passwdroot:x:0:0:root:/root:/bin/bashsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltoperator:x:11:0:operator:/root:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinCOP 4342Fall 2006 Shell programming, part 4groff and gtbl☞ There are a lot of great packages out there, such asgraphviz. A handy one is groff, a derivative of theancient troff and nroff families. (“roff” comes from“runoff”; man pages are traditionally written in nroffformat.)☞ You can use gtbl with groff to quickly make nicePostScript tables.gtbl some.tr | groff > /tmp/some.psCOP 4342Fall 2006 Shell programming, part 4fmtAnother great little utility is fmt which lets you quicklyreformat a document.You can use -w to control the width. fmt also prefersto see two spaces after a question mark, period, orexclamation point to indicate the end of a sentence.COP 4342Fall 2006 Shell programming, part 4fmt example[langley@sophie 2006-Fall]$ cat lincoln.txt Four scoreand seven ye ars ago our fathers brought forth on thiscontinent, a new nation, conceived in Liberty, anddedicated to the proposition that all men are createdequal.Now we are engaged in a great civil war, testing whetherthat nation, or any nation so conceived and so dedicated,can long endure. We are met on a great battle-field ofthat war. We have c ome to dedicate a portion of thatCOP 4342Fall 2006 Shell programming, part 4field, as a final re sting place for those who here gave theirlives that that nation might live . It is altogether fittingand prope r that we should do this.COP 4342Fall 2006 Shell programming, part 4fmt example[langley@sophie 2006-Fall]$ fmt lincoln.txtFour score and seven years ago our fathers brought forth on thiscontinent, a new nation, conceived in Liberty, and dedicated to theproposition that all men are created equal.Now we are engaged in a great civil war, testing whether that nation,or any nation so conceived and so dedicated, can long endure. We are meton a great battle-field of that war. We have come to dedicate a portionof that field, as a final resting place for those who here gave theirlives that that nation might live. It is altogether fitting and properthat we should do this.COP 4342Fall 2006 Shell programming, part 4fmt example[langley@sophie 2006-Fall]$ fmt -w 20 lincoln.txtFour score andseven years ago ourfathers broughtforth on thiscontinent, a newnation, conceivedin Liberty, anddedicated to theproposition thatall men are createdequal.COP 4342Fall 2006 Shell programming, part 4cut☞ cut allows you to extract columnar portions of a file.The columns can be specified either by a delimiter (thedefault delimiter is the tab character.)☞ You can specify a delimiter with the -d option.☞ You must


View Full Document

FSU COP 4342 - More tr Example

Download More tr Example
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view More tr Example and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view More tr Example 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?