[problem]
- You want to compare 2 streams, with byte offset and line numbers?
- Pull off content with a byte offset?
- Display lines before or after a pattern?
- Send an email – upon job failure?
[/problem]
[solution]
The shell is a powerful beast! Anything is possible … with a little know-how. 🙂 See the examples.
[/solution]
[example]
md5sum TARBALL | awk '{print $1;}' | cmp - TARBALL.md5
# cmp good for comparing output with file contents, or diffing files. Outputs byte offset and line number. md5sum creates a hash (checksum) of file.dd bs=1 skip=106 if=infile
# disk to disk copy, example outputs infile with offset of 106 bytes (block size of 1 byte, skip 106 bytes).- Ever needed to display a line before or after a pattern. Yep sure you can use Perl, but this is a bit simplier to work out.
See a run through screen shot here
Usage – ppgrep #1 #2 pattern file – where #1 is the number of lines prior to the pattern (could be 0) and #2 is number of lines post pattern.
- Sending email upon UNIX cron failure
- Linux Man Pages – dd command
- Linux Man Pages – cmp command
- Linux Man Pages – md5sum command
- Linux Man Pages – grep command
- Linux Man Pages – sed command
- Linux Man Pages – crontab command
[/example]
[reference]
[tags]dd, cmp, md5sum, grep, sed, Unix Coding School[/tags]
[/reference]
If you have found my website useful, please consider buying me a coffee below 😉