Line Buffering

So I had this problem where I 'tail'-ed a file, and 'awk'-ed the results, and that worked fine.

After that I wanted to further 'sed' the outcome of the 'awk', and there's where things went wrong, i.e. no output.

So after a decent search I found that 'awk' buffers the output, and I had to 'unbuffer' that. Some 'awk's seem to have an option to switch that on or off, but not on FreeBSD (at least, I didn't find it). So I found something cool:

stdbuf -oL

Put this in front of the buffering command unbuffers the output, and then things start working again:

Extracting a date from a file name

Whenever you have a shell script that handles a file with a date (or some other information) and you want to use that, you can do the following:


# obviously, my file is a csv-file, and I'm stripping the extension and the path.
# the file is called somefile-20160308.csv
FILE=`basename /somepath/somefile* .csv`

# the following line extracts the date
DATE=`expr "$FILE" : ".........\(........\)"`

echo $FILE
echo $DATE
Subscribe to RSS - freebsd