I have a date as 12/12/2013 14:32
I want to convert it into only 12/12/2013
. The string can be 1/1/2013 12:32
or 1/10/2013 23:41
I need only the date part.
awk to print the first column. The first column of any file can be printed by using $1 variable in awk. But if the value of the first column contains multiple words then only the first word of the first column prints. By using a specific delimiter, the first column can be printed properly.
Here, \t is used as a field separator to print the first column of the file. The '-F' option is used to set the field separator.
head with the option "-1" displays the first line. 2. The best of all options since it uses an internal command. read command is used to take user input from the standard input in shell.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With