Tuesday, April 4, 2017

Bash: Scripting - mktemp and tail

#!/bin/bash
#
# temp_tail.sh
# View states file
# Write results to temp file ($temp)
# $(mktemp) Creates temp file in /tmp
# tr "" "\n" translate spaces into newlines
# tail -3: view the bottom 3 lines
#

STATES=/auto/home/homeb/d54712/sandbox/scripts/data.d/states
temp=$(mktemp)
$((cat $STATES)> $temp |tr " " "\n")


tail -3 $temp


Results:
$ cat states
Alabama
Alaska
Arizona
Arkansas
Colorado
Connecticut
Delaware
Florida
Georgia

Results:
$ ./temp_tail.sh
Delaware
Florida
Georgia

No comments:

Post a Comment