bash - How can I get the hostname from a file using awk and regex or substring -
the file name in format this:
yyyy-mm-dd_hostname_something.log
i want hostname filename. hostname can length, has _ before , after. current awk statement. worked fine until hostname length changed. can't use anymore.
awk 'begin { ofs = "," } fnr == 1 { d = substr(filename, 1, 10) } { h = substr(filename, 12, 10) } $2 ~ /^[ap]m$/ && $3 != "cpu" { print d, $1 "" $2, h, $4+$5, $6, $7+$8+$9}' *_something.log > myfile.log
echo 'yyyy-mm-dd_hostname_something.log' | awk -f"_" '{print $2}'
output:
hostname
i suppose hostname contains no _
.
Comments
Post a Comment