Using AWK in Linux
Updated May 12, 2005
Created March 21, 2002


Autogenerated Site Map
Search this Site!:
Search this site powered by FreeFind

prev next index
cat vi.html | awk '{sub("\r",""); print}' > vi.html.new
cat for.html | awk '{gsub("\r$",""); print}' > for.html.1; mv for.html.1 for.html
# To print selective sections, when "Match_string_begin" is found then printing
# is turned off.  When "Match_string_end" is found then printing is turned
# back on.  "Match_string_end" is not printed due to the "next" awk command
# shown here.
cat my_file | awk "BEGIN { PRINTVAR = 1 } /MATCH_STRING_BEGIN/ { PRINTVAR = 0 } 
              /MATCH_STRING_END/ { PRINTVAR = 1; next } { if ( PRINTVAR == 1 ) print}"
cat my_file | awk "BEGIN { PRINTVAR = 0} /<mymatch>/ { PRINTVAR = 1; next } 
              /<\/mymatch>/ { PRINTVAR = 0; next } { if ( PRINTVAR == 1 ) print}"
(the above has matching <mymatch> and </mymatch> strings on lines by 
 themselves to turn on and off printed sections)
I word wrapped the above 2 examples, be sure to enter yours as a single line.

The following breaks apart a single patchfile into separate filenames (I haven't made it fancy yet)
(it just starts couting from 1 and goes up until no more patchfiles)
cat patch.diff | awk 'BEGIN {count=1} /^diff/ {filename=count++} {print >> filename}'
(I would like to name it like p1, p2, p3, or even better grab the filename
from the "diff" line or --- and +++ lines, but I'll have to learn that later.)

prev next index
Search this Site!:
Search this site powered by FreeFind

Homepage: http://www.cpqlinux.com
Site Map: http://www.cpqlinux.com/sitemap.html