Here is another guest post by Mary M. Chaddock. She is a Network Security Administrator for a major university in Texas. Here is her time saving tip. Thanks Mary.
This little routine searches a file for a string and then prints the paragraph associated with that string.
Note: The Blogger application parsed out the greater-than and less-than characters so an underscore was used to preserve the contiguous nature of the <_string> <_filename> symbols.
Mary says…
Grep'ing from a file with more than one line per record:
You can do this with a Perl one-liner command: 'perl -00 -ne 'print if /'<_gstring>'/' <_filename>'
But I can rarely remember the Perl syntax, so I put this small shell script in my $HOME/bin directory:
#!/bin/sh
#
# grep a string in a paragraph and print the paragraph.
# A paragraph is delimited by a blank line.
#
# syntax: gparagraph <_string> <_filename>
#
gstring=$1
gfile=$2
perl -00 -ne 'print if /'$gstring'/' $gfile
This blog covers Unix system administration HOWTO tips for using inline for loops, find command, Unix scripting, configuration, SQL, various Unix-based tools, and command line interface syntax. The Unix OS supports tasks such as running hardware, device drivers, peripherals and third party applications. Share tips/comments. Read the comments. But most importantly: Read Disclaimer - Read Disclaimer.
Subscribe to:
Post Comments (Atom)
1 comment:
Hello from Spain.
Post a Comment