<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Aniline's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 06 Aug 2008 12:08:57 GMT</pubDate>
    <description>DZone Snippets: Aniline's Code Snippets</description>
    <item>
      <title>SED by itself</title>
      <link>http://snippets.dzone.com/posts/show/4894</link>
      <description>//SED examples&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;grep widget mlb | awk '{print $3}' | sed 's/--&gt;/ /g'&lt;br /&gt;&lt;br /&gt;sed sub --&gt; with blank space g= global&lt;br /&gt;&lt;br /&gt; # substitute "foo" with "bar" ONLY for lines which contain "baz"&lt;br /&gt; sed '/baz/s/foo/bar/g'&lt;br /&gt;&lt;br /&gt; # substitute "foo" with "bar" EXCEPT for lines which contain "baz"&lt;br /&gt; sed '/baz/!s/foo/bar/g'&lt;br /&gt;&lt;br /&gt; # change "scarlet" or "ruby" or "puce" to "red"&lt;br /&gt; sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g'   # most seds&lt;br /&gt; gsed 's/scarlet\|ruby\|puce/red/g'      &lt;br /&gt;&lt;br /&gt;Substitute newlines for &amp;&lt;br /&gt;sed -e 's/&amp;/\n/g' test.txt &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Dec 2007 00:11:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4894</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>AWK more of it.</title>
      <link>http://snippets.dzone.com/posts/show/4893</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;MORE AWK&lt;br /&gt;&lt;br /&gt;HANDY ONE-LINERS FOR AWK                                  22 July 2003&lt;br /&gt;compiled by Eric Pement &lt;pemente@northpark.edu&gt;           version 0.22&lt;br /&gt;   Latest version of this file is usually at:&lt;br /&gt;   http://www.student.northpark.edu/pemente/awk/awk1line.txt&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;USAGE:&lt;br /&gt;&lt;br /&gt;    Unix:  awk '/pattern/ {print "$1"}'    # standard Unix shells&lt;br /&gt; DOS/Win:  awk '/pattern/ {print "$1"}'    # okay for DJGPP compiled&lt;br /&gt;           awk "/pattern/ {print \"$1\"}"  # required for Mingw32&lt;br /&gt;&lt;br /&gt;Most of my experience comes from version of GNU awk (gawk) compiled for&lt;br /&gt;Win32. Note in particular that DJGPP compilations permit the awk script&lt;br /&gt;to follow Unix quoting syntax '/like/ {"this"}'. However, the user must&lt;br /&gt;know that single quotes under DOS/Windows do not protect the redirection&lt;br /&gt;arrows (&lt;, &gt;) nor do they protect pipes (|). Both are special symbols&lt;br /&gt;for the DOS/CMD command shell and their special meaning is ignored only&lt;br /&gt;if they are placed within "double quotes." Likewise, DOS/Win users must&lt;br /&gt;remember that the percent sign (%) is used to mark DOS/Win environment&lt;br /&gt;variables, so it must be doubled (%%) to yield a single percent sign&lt;br /&gt;visible to awk.&lt;br /&gt;&lt;br /&gt;If I am sure that a script will NOT need to be quoted in Unix, DOS, or&lt;br /&gt;CMD, then I normally omit the quote marks. If an example is peculiar to&lt;br /&gt;GNU awk, the command 'gawk' will be used. Please notify me if you find&lt;br /&gt;errors or new commands to add to this list (total length under 65&lt;br /&gt;characters). I usually try to put the shortest script first.&lt;br /&gt;&lt;br /&gt;FILE SPACING:&lt;br /&gt;&lt;br /&gt; # double space a file&lt;br /&gt; awk '1;{print ""}'&lt;br /&gt; awk 'BEGIN{ORS="\n\n"};1'&lt;br /&gt;&lt;br /&gt; # double space a file which already has blank lines in it. Output file&lt;br /&gt; # should contain no more than one blank line between lines of text.&lt;br /&gt; # NOTE: On Unix systems, DOS lines which have only CRLF (\r\n) are&lt;br /&gt; # often treated as non-blank, and thus 'NF' alone will return TRUE.&lt;br /&gt; awk 'NF{print $0 "\n"}'&lt;br /&gt;&lt;br /&gt; # triple space a file&lt;br /&gt; awk '1;{print "\n"}'&lt;br /&gt;&lt;br /&gt;NUMBERING AND CALCULATIONS:&lt;br /&gt;&lt;br /&gt; # precede each line by its line number FOR THAT FILE (left alignment).&lt;br /&gt; # Using a tab (\t) instead of space will preserve margins.&lt;br /&gt; awk '{print FNR "\t" $0}' files*&lt;br /&gt;&lt;br /&gt; # precede each line by its line number FOR ALL FILES TOGETHER, with tab.&lt;br /&gt; awk '{print NR "\t" $0}' files*&lt;br /&gt;&lt;br /&gt; # number each line of a file (number on left, right-aligned)&lt;br /&gt; # Double the percent signs if typing from the DOS command prompt.&lt;br /&gt; awk '{printf("%5d : %s\n", NR,$0)}'&lt;br /&gt;&lt;br /&gt; # number each line of file, but only print numbers if line is not blank&lt;br /&gt; # Remember caveats about Unix treatment of \r (mentioned above)&lt;br /&gt; awk 'NF{$0=++a " :" $0};{print}'&lt;br /&gt; awk '{print (NF? ++a " :" :"") $0}'&lt;br /&gt;&lt;br /&gt; # count lines (emulates "wc -l")&lt;br /&gt; awk 'END{print NR}'&lt;br /&gt;&lt;br /&gt; # print the sums of the fields of every line&lt;br /&gt; awk '{s=0; for (i=1; i&lt;=NF; i++) s=s+$i; print s}'&lt;br /&gt;&lt;br /&gt; # add all fields in all lines and print the sum&lt;br /&gt; awk '{for (i=1; i&lt;=NF; i++) s=s+$i}; END{print s}'&lt;br /&gt;&lt;br /&gt; # print every line after replacing each field with its absolute value&lt;br /&gt; awk '{for (i=1; i&lt;=NF; i++) if ($i &lt; 0) $i = -$i; print }'&lt;br /&gt; awk '{for (i=1; i&lt;=NF; i++) $i = ($i &lt; 0) ? -$i : $i; print }'&lt;br /&gt;&lt;br /&gt; # print the total number of fields ("words") in all lines&lt;br /&gt; awk '{ total = total + NF }; END {print total}' file&lt;br /&gt;&lt;br /&gt; # print the total number of lines that contain "Beth"&lt;br /&gt; awk '/Beth/{n++}; END {print n+0}' file&lt;br /&gt;&lt;br /&gt; # print the largest first field and the line that contains it&lt;br /&gt; # Intended for finding the longest string in field #1&lt;br /&gt; awk '$1 &gt; max {max=$1; maxline=$0}; END{ print max, maxline}'&lt;br /&gt;&lt;br /&gt; # print the number of fields in each line, followed by the line&lt;br /&gt; awk '{ print NF ":" $0 } '&lt;br /&gt;&lt;br /&gt; # print the last field of each line&lt;br /&gt; awk '{ print $NF }'&lt;br /&gt;&lt;br /&gt; # print the last field of the last line&lt;br /&gt; awk '{ field = $NF }; END{ print field }'&lt;br /&gt;&lt;br /&gt; # print every line with more than 4 fields&lt;br /&gt; awk 'NF &gt; 4'&lt;br /&gt;&lt;br /&gt; # print every line where the value of the last field is &gt; 4&lt;br /&gt; awk '$NF &gt; 4'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TEXT CONVERSION AND SUBSTITUTION:&lt;br /&gt;&lt;br /&gt; # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format&lt;br /&gt; awk '{sub(/\r$/,"");print}'   # assumes EACH line ends with Ctrl-M&lt;br /&gt;&lt;br /&gt; # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format&lt;br /&gt; awk '{sub(/$/,"\r");print}&lt;br /&gt;&lt;br /&gt; # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format&lt;br /&gt; awk 1&lt;br /&gt;&lt;br /&gt; # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format&lt;br /&gt; # Cannot be done with DOS versions of awk, other than gawk:&lt;br /&gt; gawk -v BINMODE="w" '1' infile &gt;outfile&lt;br /&gt;&lt;br /&gt; # Use "tr" instead.&lt;br /&gt; tr -d \r &lt;infile &gt;outfile            # GNU tr version 1.22 or higher&lt;br /&gt;&lt;br /&gt; # delete leading whitespace (spaces, tabs) from front of each line&lt;br /&gt; # aligns all text flush left&lt;br /&gt; awk '{sub(/^[ \t]+/, ""); print}'&lt;br /&gt;&lt;br /&gt; # delete trailing whitespace (spaces, tabs) from end of each line&lt;br /&gt; awk '{sub(/[ \t]+$/, "");print}'&lt;br /&gt;&lt;br /&gt; # delete BOTH leading and trailing whitespace from each line&lt;br /&gt; awk '{gsub(/^[ \t]+|[ \t]+$/,"");print}'&lt;br /&gt; awk '{$1=$1;print}'           # also removes extra space between fields&lt;br /&gt;&lt;br /&gt; # insert 5 blank spaces at beginning of each line (make page offset)&lt;br /&gt; awk '{sub(/^/, "     ");print}'&lt;br /&gt;&lt;br /&gt; # align all text flush right on a 79-column width&lt;br /&gt; awk '{printf "%79s\n", $0}' file*&lt;br /&gt;&lt;br /&gt; # center all text on a 79-character width&lt;br /&gt; awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' file*&lt;br /&gt;&lt;br /&gt; # substitute (find and replace) "foo" with "bar" on each line&lt;br /&gt; awk '{sub(/foo/,"bar");print}'           # replaces only 1st instance&lt;br /&gt; gawk '{$0=gensub(/foo/,"bar",4);print}'  # replaces only 4th instance&lt;br /&gt; awk '{gsub(/foo/,"bar");print}'          # replaces ALL instances in a line&lt;br /&gt;&lt;br /&gt; # substitute "foo" with "bar" ONLY for lines which contain "baz"&lt;br /&gt; awk '/baz/{gsub(/foo/, "bar")};{print}'&lt;br /&gt;&lt;br /&gt; # substitute "foo" with "bar" EXCEPT for lines which contain "baz"&lt;br /&gt; awk '!/baz/{gsub(/foo/, "bar")};{print}'&lt;br /&gt;&lt;br /&gt; # change "scarlet" or "ruby" or "puce" to "red"&lt;br /&gt; awk '{gsub(/scarlet|ruby|puce/, "red"); print}'&lt;br /&gt;&lt;br /&gt; # reverse order of lines (emulates "tac")&lt;br /&gt; awk '{a[i++]=$0} END {for (j=i-1; j&gt;=0;) print a[j--] }' file*&lt;br /&gt;&lt;br /&gt; # if a line ends with a backslash, append the next line to it&lt;br /&gt; # (fails if there are multiple lines ending with backslash...)&lt;br /&gt; awk '/\\$/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' file*&lt;br /&gt;&lt;br /&gt; # print and sort the login names of all users&lt;br /&gt; awk -F ":" '{ print $1 | "sort" }' /etc/passwd&lt;br /&gt;&lt;br /&gt; # print the first 2 fields, in opposite order, of every line&lt;br /&gt; awk '{print $2, $1}' file&lt;br /&gt;&lt;br /&gt; # switch the first 2 fields of every line&lt;br /&gt; awk '{temp = $1; $1 = $2; $2 = temp}' file&lt;br /&gt;&lt;br /&gt; # print every line, deleting the second field of that line&lt;br /&gt; awk '{ $2 = ""; print }'&lt;br /&gt;&lt;br /&gt; # print in reverse order the fields of every line&lt;br /&gt; awk '{for (i=NF; i&gt;0; i--) printf("%s ",i);printf ("\n")}' file&lt;br /&gt;&lt;br /&gt; # remove duplicate, consecutive lines (emulates "uniq")&lt;br /&gt; awk 'a !~ $0; {a=$0}'&lt;br /&gt;&lt;br /&gt; # remove duplicate, nonconsecutive lines&lt;br /&gt; awk '! a[$0]++'                     # most concise script&lt;br /&gt; awk '!($0 in a) {a[$0];print}'      # most efficient script&lt;br /&gt;&lt;br /&gt; # concatenate every 5 lines of input, using a comma separator&lt;br /&gt; # between fields&lt;br /&gt; awk 'ORS=NR%5?",":"\n"' file&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECTIVE PRINTING OF CERTAIN LINES:&lt;br /&gt;&lt;br /&gt; # print first 10 lines of file (emulates behavior of "head")&lt;br /&gt; awk 'NR &lt; 11'&lt;br /&gt;&lt;br /&gt; # print first line of file (emulates "head -1")&lt;br /&gt; awk 'NR&gt;1{exit};1'&lt;br /&gt;&lt;br /&gt;  # print the last 2 lines of a file (emulates "tail -2")&lt;br /&gt; awk '{y=x "\n" $0; x=$0};END{print y}'&lt;br /&gt;&lt;br /&gt; # print the last line of a file (emulates "tail -1")&lt;br /&gt; awk 'END{print}'&lt;br /&gt;&lt;br /&gt; # print only lines which match regular expression (emulates "grep")&lt;br /&gt; awk '/regex/'&lt;br /&gt;&lt;br /&gt; # print only lines which do NOT match regex (emulates "grep -v")&lt;br /&gt; awk '!/regex/'&lt;br /&gt;&lt;br /&gt; # print the line immediately before a regex, but not the line&lt;br /&gt; # containing the regex&lt;br /&gt; awk '/regex/{print x};{x=$0}'&lt;br /&gt; awk '/regex/{print (x=="" ? "match on line 1" : x)};{x=$0}'&lt;br /&gt;&lt;br /&gt; # print the line immediately after a regex, but not the line&lt;br /&gt; # containing the regex&lt;br /&gt; awk '/regex/{getline;print}'&lt;br /&gt;&lt;br /&gt; # grep for AAA and BBB and CCC (in any order)&lt;br /&gt; awk '/AAA/; /BBB/; /CCC/'&lt;br /&gt;&lt;br /&gt; # grep for AAA and BBB and CCC (in that order)&lt;br /&gt; awk '/AAA.*BBB.*CCC/'&lt;br /&gt;&lt;br /&gt; # print only lines of 65 characters or longer&lt;br /&gt; awk 'length &gt; 64'&lt;br /&gt;&lt;br /&gt; # print only lines of less than 65 characters&lt;br /&gt; awk 'length &lt; 64'&lt;br /&gt;&lt;br /&gt; # print section of file from regular expression to end of file&lt;br /&gt; awk '/regex/,0'&lt;br /&gt; awk '/regex/,EOF'&lt;br /&gt;&lt;br /&gt; # print section of file based on line numbers (lines 8-12, inclusive)&lt;br /&gt; awk 'NR==8,NR==12'&lt;br /&gt;&lt;br /&gt; # print line number 52&lt;br /&gt; awk 'NR==52'&lt;br /&gt; awk 'NR==52 {print;exit}'          # more efficient on large files&lt;br /&gt;&lt;br /&gt; # print section of file between two regular expressions (inclusive)&lt;br /&gt; awk '/Iowa/,/Montana/'             # case sensitive&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECTIVE DELETION OF CERTAIN LINES:&lt;br /&gt;&lt;br /&gt; # delete ALL blank lines from a file (same as "grep '.' ")&lt;br /&gt; awk NF&lt;br /&gt; awk '/./'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;CREDITS AND THANKS:&lt;br /&gt;&lt;br /&gt;Special thanks to Peter S. Tillier for helping me with the first release&lt;br /&gt;of this FAQ file.&lt;br /&gt;&lt;br /&gt;For additional syntax instructions, including the way to apply editing&lt;br /&gt;commands from a disk file instead of the command line, consult:&lt;br /&gt;&lt;br /&gt;"sed &amp; awk, 2nd Edition," by Dale Dougherty and Arnold Robbins&lt;br /&gt;  O'Reilly, 1997&lt;br /&gt;"UNIX Text Processing," by Dale Dougherty and Tim O'Reilly&lt;br /&gt;  Hayden Books, 1987&lt;br /&gt;"Effective awk Programming, 3rd Edition." by Arnold Robbins&lt;br /&gt;  O'Reilly, 2001&lt;br /&gt;&lt;br /&gt;To fully exploit the power of awk, one must understand "regular&lt;br /&gt;expressions." For detailed discussion of regular expressions, see&lt;br /&gt;"Mastering Regular Expressions, 2d edition" by Jeffrey Friedl&lt;br /&gt;   (O'Reilly, 2002).&lt;br /&gt;&lt;br /&gt;The manual ("man") pages on Unix systems may be helpful (try "man awk",&lt;br /&gt;"man nawk", "man regexp", or the section on regular expressions in "man&lt;br /&gt;ed"), but man pages are notoriously difficult. They are not written to&lt;br /&gt;teach awk use or regexps to first-time users, but as a reference text&lt;br /&gt;for those already acquainted with these tools.&lt;br /&gt;&lt;br /&gt;USE OF '\t' IN awk SCRIPTS: For clarity in documentation, we have used&lt;br /&gt;the expression '\t' to indicate a tab character (0x09) in the scripts.&lt;br /&gt;All versions of awk, even the UNIX System 7 version should recognize&lt;br /&gt;the '\t' abbreviation.&lt;br /&gt;&lt;br /&gt;#---end of file---&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Dec 2007 00:11:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4893</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>RSYNC</title>
      <link>http://snippets.dzone.com/posts/show/4892</link>
      <description>// RSYNC usage&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;rsync -e ssh atayebali@qafeed1:/usr/local/aolserver/servers/fs/pages/livexml/MLB/MLB_TRANS.XML rysnc_test.xml&lt;br /&gt;&lt;br /&gt;rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST&lt;br /&gt;  or   rsync [OPTION]... [USER@]HOST:SRC DEST&lt;br /&gt;  or   rsync [OPTION]... SRC [SRC]... DEST&lt;br /&gt;  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]&lt;br /&gt;  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST&lt;br /&gt;  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]&lt;br /&gt;  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST&lt;br /&gt;SRC on single-colon remote HOST will be expanded by remote shell&lt;br /&gt;SRC on server remote HOST may contain shell wildcards or multiple&lt;br /&gt;  sources separated by space as long as they have same top-level&lt;br /&gt;&lt;br /&gt;copying folders&lt;br /&gt;&lt;br /&gt;rsync -e ssh -r atayebali@dev.foxsports.com:/path folder/&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Dec 2007 00:10:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4892</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>All kinds of code</title>
      <link>http://snippets.dzone.com/posts/show/4891</link>
      <description>Case Switch&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	echo "enter something&gt;&gt;" &lt;br /&gt;4	read var &lt;br /&gt;5	 &lt;br /&gt;6	case $var in &lt;br /&gt;7	1 ) echo "1" ;; &lt;br /&gt;8	2 ) echo "2" ;; &lt;br /&gt;9	an* ) echo "not" ;; &lt;br /&gt;10	*tom ) echo "wow" ;; &lt;br /&gt;11	*) echo "end" &lt;br /&gt;12	esac &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash echo "enter something&gt;&gt;" read var case $var in 1 ) echo "1" ;; 2 ) echo "2" ;; an* ) echo "not" ;; *tom ) echo "wow" ;; *) echo "end" esac&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Find Files&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	find . -name "*" -size 0k &gt; file1.txt &lt;br /&gt;4	sed -e 's/\.\///g' file1.txt &gt; file2.txt &lt;br /&gt;5	for line in `cat 0sizenuggets1.txt`; do ls -l $line; done &gt; finalResult.txt &lt;br /&gt;6	uuencode finalResult.txt finalresult.txt | mail -s "size 0 nuggets" atayebali@foxsports.com &lt;br /&gt;7	rm file1.txt file2.txt &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash find . -name "*" -size 0k &gt; file1.txt sed -e 's/\.\///g' file1.txt &gt; file2.txt for line in `cat 0sizenuggets1.txt`; do ls -l $line; done &gt; finalResult.txt uuencode finalResult.txt finalresult.txt | mail -s "size 0 nuggets" atayebali@foxsports.com rm file1.txt file2.txt&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Get Time&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	wget -O tf http://nist.time.gov/timezone.cgi?Pacific/d/-8 &lt;br /&gt;4	grep '&gt;[0-9][0-9]:[0-9][0-9]'  tf | cut -c63-70 &lt;br /&gt;5	echo "PST" &lt;br /&gt;6	rm tf &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash wget -O tf http://nist.time.gov/timezone.cgi?Pacific/d/-8 grep '&gt;[0-9][0-9]:[0-9][0-9]' tf | cut -c63-70 echo "PST" rm tf&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;If Statement Example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	echo "$1" &lt;br /&gt;4	 &lt;br /&gt;5	if [ "$1" == hello ]; then &lt;br /&gt;6	        echo "hello there" &lt;br /&gt;7	else &lt;br /&gt;8	        echo "By nice" &lt;br /&gt;9	fi &lt;br /&gt;10	 &lt;br /&gt;11	checking for directories &lt;br /&gt;12	 &lt;br /&gt;13	if [ -d "DB/" ] &lt;br /&gt;14	 then &lt;br /&gt;15	        rm -rf DB &lt;br /&gt;16	        echo "killing DB folder" &lt;br /&gt;17	 fi &lt;br /&gt;18	 &lt;br /&gt;19	checking for files &lt;br /&gt;20	if [ -f "DB/" ] &lt;br /&gt;21	 then &lt;br /&gt;22	        rm -rf DB &lt;br /&gt;23	        echo "killing DB folder" &lt;br /&gt;24	 fi &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash echo "$1" if [ "$1" == hello ]; then echo "hello there" else echo "By nice" fi checking for directories if [ -d "DB/" ] then rm -rf DB echo "killing DB folder" fi checking for files if [ -f "DB/" ] then rm -rf DB echo "killing DB folder" fi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Sed Example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	for line in `ls` &lt;br /&gt;4	do &lt;br /&gt;5	        sed -e 's/Spring/Regular Season/g' line &gt; tmp &lt;br /&gt;6	        mv tmp line &lt;br /&gt;7	        echo -n $line &lt;br /&gt;8	        grep Regular $line &lt;br /&gt;9	done &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash for line in `ls` do sed -e 's/Spring/Regular Season/g' line &gt; tmp mv tmp line echo -n $line grep Regular $line done&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;While Example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	echo "enter number: " &lt;br /&gt;4	read var &lt;br /&gt;5	 &lt;br /&gt;6	while [ $var -le 10 ]; do &lt;br /&gt;7	echo "var is $var" &lt;br /&gt;8	var=$((var + 1)) &lt;br /&gt;9	done &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash echo "enter number: " read var while [ $var -le 10 ]; do echo "var is $var" var=$((var + 1)) done&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Email Example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	function email &lt;br /&gt;4	{ &lt;br /&gt;5	echo "this is a test" | mail -s "test" "$1" &lt;br /&gt;6	} &lt;br /&gt;7	 &lt;br /&gt;8	if [ "$1" = "" ]; then &lt;br /&gt;9	echo "nothing in param" &lt;br /&gt;10	else &lt;br /&gt;11	echo "sending mail" &lt;br /&gt;12	 &lt;br /&gt;13	#emailing attachment &lt;br /&gt;14	#uuencode statsNbaAllStarSim statssim | mail -s "test attachement" atayebali@foxsports.com &lt;br /&gt;15	#uuencode &lt;filename that will be send&gt; &lt;name for attached file that is sent&gt; | &lt;br /&gt;16	 &lt;br /&gt;17	#passing the param to function &lt;br /&gt;18	email $1 &lt;br /&gt;19	fi &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash function email { echo "this is a test" | mail -s "test" "$1" } if [ "$1" = "" ]; then echo "nothing in param" else echo "sending mail" #emailing attachment #uuencode statsNbaAllStarSim statssim | mail -s "test attachement" atayebali@foxsports.com #uuencode &lt;filename that will be send&gt; &lt;name for attached file that is sent&gt; | #passing the param to function email $1 fi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Function Example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	 &lt;br /&gt;4	function show_uptime &lt;br /&gt;5	{ &lt;br /&gt;6	    # Temporary function stub &lt;br /&gt;7	        uptime &lt;br /&gt;8	} &lt;br /&gt;9	 &lt;br /&gt;10	      echo $(show_uptime) &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash function show_uptime { # Temporary function stub uptime } echo $(show_uptime)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Command Line Args&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	 &lt;br /&gt;4	echo "Positional Parameters" &lt;br /&gt;5	echo '$0 = ' $0 &lt;br /&gt;6	echo '$1 = ' $1 &lt;br /&gt;7	echo '$2 = ' $2 &lt;br /&gt;8	echo '$3 = ' $3 &lt;br /&gt;9	 &lt;br /&gt;10	if [ $1==hello ] ; then &lt;br /&gt;11	echo "YO MAN" &lt;br /&gt;12	fi &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash echo "Positional Parameters" echo '$0 = ' $0 echo '$1 = ' $1 echo '$2 = ' $2 echo '$3 = ' $3 if [ $1==hello ] ; then echo "YO MAN" fi&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Read User Input&lt;br /&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	echo "Hello guy what is your name?" &lt;br /&gt;4	read text &lt;br /&gt;5	echo "Hello $text" &lt;br /&gt;6	 &lt;br /&gt;7	echo $1 &lt;br /&gt;8	 &lt;br /&gt;9	echo "How old are you?" &lt;br /&gt;10	if  read -t 5 response ; then &lt;br /&gt;11	        echo "sweet" &lt;br /&gt;12	else &lt;br /&gt;13	        echo "sour" &lt;br /&gt;14	 &lt;br /&gt;15	fi &lt;br /&gt;16	 &lt;br /&gt;17	echo -n "type in secret" &lt;br /&gt;18	if  read -t 5 response ; then &lt;br /&gt;19	        echo "sweet" &lt;br /&gt;20	fi &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash echo "Hello guy what is your name?" read text echo "Hello $text" echo $1 echo "How old are you?" if read -t 5 response ; then echo "sweet" else echo "sour" fi echo -n "type in secret" if read -t 5 response ; then echo "sweet" fi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Create Cookie Script&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	function set_value &lt;br /&gt;4	{ &lt;br /&gt;5	       domain=( fox hotmail gmail ) &lt;br /&gt;6	        echo "${domain[0]}" &lt;br /&gt;7	 &lt;br /&gt;8	} &lt;br /&gt;9	 &lt;br /&gt;10	 &lt;br /&gt;11	 &lt;br /&gt;12	for line in `cat description.dat` &lt;br /&gt;13	        do &lt;br /&gt;14	 &lt;br /&gt;15	        echo $line &lt;br /&gt;16	        String=$String$line=$(set_value)\&amp; &lt;br /&gt;17	 &lt;br /&gt;18	done &lt;br /&gt;19	 &lt;br /&gt;20	echo -e  "\n\n" &lt;br /&gt;21	 &lt;br /&gt;22	echo $String &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash function set_value { domain=( fox hotmail gmail ) echo "${domain[0]}" } for line in `cat description.dat` do echo $line String=$String$line=$(set_value)\&amp; done echo -e "\n\n" echo $String&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Introduce a new line&lt;br /&gt;&lt;code&gt;&lt;br /&gt;1	#!/bin/bash &lt;br /&gt;2	 &lt;br /&gt;3	#Introduce a new line after every '&amp;' in the test.txt file &lt;br /&gt;4	 &lt;br /&gt;5	sed -e 's/&amp;/\n/g' test.txt &lt;br /&gt;	view plain | print | ?&lt;br /&gt;#!/bin/bash #Introduce a new line after every '&amp;' in the test.txt file sed -e 's/&amp;/\n/g' test.txt &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 13 Dec 2007 00:09:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4891</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>Permissions</title>
      <link>http://snippets.dzone.com/posts/show/4890</link>
      <description>// Triplets explained&lt;br /&gt;chmod 755&lt;br /&gt;&lt;br /&gt; Triplet for u: rwx =&gt; 4 + 2 + 1 = 7&lt;br /&gt;Triplet for g: r-x =&gt; 4 + 0 + 1 = 5&lt;br /&gt;Tripler for o: r-x =&gt; 4 + 0 + 1 = 5&lt;br /&gt;Which makes : 755</description>
      <pubDate>Thu, 13 Dec 2007 00:04:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4890</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>AWK &amp; SED Constructs</title>
      <link>http://snippets.dzone.com/posts/show/4889</link>
      <description>// Various awk and sed combinations.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;awk &amp; Sed construct&lt;br /&gt;&lt;br /&gt;View lines  500 to 505&lt;br /&gt;awk 'NR &gt;= 500 &amp;&amp; NR &lt;= 505'&lt;br /&gt;&lt;br /&gt;remove blank lines&lt;br /&gt;sed -e /^$/d data &gt; filename&lt;br /&gt;&lt;br /&gt;remove tabs :&lt;br /&gt;&lt;br /&gt; sed 's/^[ \t]*//' data_raw &gt; data_raw1&lt;br /&gt;&lt;br /&gt;search and replace words with escape:&lt;br /&gt;&lt;br /&gt;sed -e '/\/id\//d' urls.dat &gt; urlsnostory.dat&lt;br /&gt;&lt;br /&gt;awk '{print $3,$2}' emp_names&lt;br /&gt;&lt;br /&gt;awk '/AL/ {print $3,$2}' emp_names&lt;br /&gt;&lt;br /&gt;what I used&lt;br /&gt;awk '{print $1}' parsed_hrefs &gt;&gt; finalcut&lt;br /&gt;&lt;br /&gt; awk '/href\=\"(.*) / {print $2}' hrefs pinr&lt;br /&gt;&lt;br /&gt;awk '{print $NF}' wnba -- Print last line of the code.&lt;br /&gt;&lt;br /&gt;-----------------------&lt;br /&gt;Extracting from live xml&lt;br /&gt;awk '/gameId=/{print "/nugget/100_5_" substr($5,9,11)}' ts&lt;br /&gt; awk '/gamecode/{print "/nugget/100_73_" substr($2,7,10)}' nba&lt;br /&gt;awk '/gamecode/{print "/nugget/100_49_" substr($2,7,9)}' mlb&lt;br /&gt;&lt;br /&gt;----------------------------&lt;br /&gt;&lt;br /&gt;Extracting gameIds from scores page&lt;br /&gt;awk '/gamecode code=*/ {print substr($2,28,10)}' nbascores&lt;br /&gt;&lt;br /&gt;CBK:&lt;br /&gt;awk '/gamecode code=*/ {print substr($2,7,12)}' cbk&lt;br /&gt;&lt;br /&gt;Extracting headers&lt;br /&gt;awk '{print $1 " " $2 " " $3 " &lt;img src=\"http://jqa.foxsports.com/fe/img/Writers/header/" $3 ".jpg\"&gt; " "&lt;br&gt;"}' authwids &lt;br /&gt;&lt;br /&gt;Field Seperator&lt;br /&gt;awk -F\\ '{print $6}' logos  [ The \\ escape is added ]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Dec 2007 23:51:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4889</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>FIND &amp; AWK combination</title>
      <link>http://snippets.dzone.com/posts/show/4888</link>
      <description>// File name extraction&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;substr(field, position, number_of_characters)&lt;br /&gt;&lt;br /&gt; find |  awk '/MLB_LIVE/ {print substr($0, 21,6)}' | sort&lt;br /&gt;&lt;br /&gt;in a script (parse and save to tmp file:&lt;br /&gt;&lt;br /&gt;for string in $( find |  awk '/MLB_LIVE/ {print substr($0, 21,6)}'  ); do echo $string; done &gt; tmp&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Extract from ping&lt;br /&gt;ping qafeed1 | awk ' {print substr($8, 6, 9)}'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Dec 2007 23:48:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4888</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>FIND</title>
      <link>http://snippets.dzone.com/posts/show/4887</link>
      <description>// find by name&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find . -name '*3079716*'&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// find file extensions&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find | cut -d "." -f3 | sort | uniq -c&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Dec 2007 23:46:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4887</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>Watch</title>
      <link>http://snippets.dzone.com/posts/show/4886</link>
      <description>// See file updates in real time&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;watch -d &lt;file or directory&gt;&lt;br /&gt;&lt;br /&gt;watch -n 2 ls&lt;br /&gt;&lt;br /&gt;watch -d -n 5 cat live.xml&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Dec 2007 23:44:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4886</guid>
      <author>aniline (Aniline)</author>
    </item>
    <item>
      <title>Find Server Type Wget</title>
      <link>http://snippets.dzone.com/posts/show/4885</link>
      <description>//Get server type.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;wget -d &lt;url&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Dec 2007 23:42:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4885</guid>
      <author>aniline (Aniline)</author>
    </item>
  </channel>
</rss>
