New answers tagged

0

I use TAB and cut in these ways: # quote the whole thing, use TAB escape cut "-d\t" -f 2 # just quote the tab escape cut -d "\t" -f 2 # Use Ctrl-V to quote Ctrl-I (TAB is Ctrl-I, see man ascii) cut -d^V^I -f 2


0

Alternatively, one could wrap cut in a function. function getColumns () { local -r delimiter="${1:?}" local -r columns="${2:?}" if [[ "$delimiter" == '\t' || "$delimter" == "tab" ]]; then cut "--fields=${columns}" return fi cut "--delimiter=${delimiter}&...


1

The answer would be no. According to the manual, the job of the command is to print selected text, not adding text: CUT(1) NAME cut - remove sections from each line of files SYNOPSIS cut OPTION... [FILE]... DESCRIPTION Print selected parts of lines from each FILE to standard output. The closest is to add a custom output delimiter: --output-delimiter=...


3

awk may be a better and easier solution for this. uptime | awk '{sub(/,/,"",$5); print "Uptime: " $3,$4,$5}'


1

You can't insert anything with cut. I would suggest using sed to insert the Uptime: string instead. uptime | sed 's/.*up/Uptime:/' | cut -d, -f -2


1

Assuming that your log files are all matched by the filename globbing pattern *.*-*.log, you may loop over their names and extract the different parts into separate variables. for name in *.*-*.log; do tmpname=$name environment=${tmpname%%.*}; tmpname=${tmpname#*.} type=${tmpname%%-*}; tmpname=${tmpname#*-} date=${...


Top 50 recent answers are included