You're really close:
date2=$(echo $date1 | cut -f3 -d\ )
should do the trick. In this case we're telling
cut
to return the 3rd field (-f3 flag), with field separator space, (-d\ flag ). Note that for the -d flag you need to make the space char significant using the backslash, otherwise the shell will treat the space a an argument separator, and will complain that option -d requires an argument.
I prefer the
$( ... )
form of command substitution, since it can be nested e.g.
cmd1 $(cmd2 $(cmd3 arg-a arg-b) arg-3 arg-4) arg-x
does what you expect: it executes cmd3 and uses the results of that as an argument to cmd2, the output of which is then passed in as an argument to cmd1.
If you know the column positions, you can save a some overhead using the
${parameter:offset:length}
Parameter substitution. In you example above
echo ${date1:7:7}
does what you want, as long as its the first 9 days of the month, which I think is what you were referring to as the "wrong approach". Bash provides several conversions like this, Look at the man page for bash and search for "Parameter Expansion" to find what is available.