Printing only the first field in a string

You can do this easily with a variety of Unix tools:

$ cut -d' ' -f1  <<< "12/12/2013 14:32"
12/12/2013

$ awk '{print $1}' <<< "12/12/2013 14:32"
12/12/2013

$ sed 's/ .*//' <<< "12/12/2013 14:32"
12/12/2013

$ grep -o "^\S\+"  <<< "12/12/2013 14:32"
12/12/2013

$ perl -lane 'print $F[0]' <<< "12/12/2013 14:32"
12/12/2013

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)