i think this should be do-able in sed/awk, right? convert the following list to 2011.08.01 ... etc
20110801
20110802
20110803
20110804
20110805
20110808
just not smart enough to figure out how to do it
any suggestiongs?
Using GNU date:
for date in 20110801 20110802 20110803 20110804 20110805 20110808; do
date -d "$date" +%Y.%m.%d
done
It barfs on invalid date.
date -d '20111214' +'%Y.%m.%d'
The inputstring can be close to everything which can be identified as a date.
export V=20111010;echo ${V:0:4}.${V:4:2}.${V:6:2}
So for your case, something like:
while read x; do echo ${x:0:4}.${x:4:2}.${x:6:2}; done
sh
.
Dec 14, 2011 at 13:07
tail=${V#????}; echo "${V%????}.${tail%??}.${tail#??}"
In sed:
sed 's/\(....\)\(..\)\(..\)/\1.\2.\3/'
As pointed out by potong in a comment, it's not actually necessary to specify all three groups. You could instead use
sed 's/\(....\)\(..\)/\1.\2./'
gawk
gawk '/^[0-9]+$/{print substr($0,1,4)"."substr($0,5,2)"."substr($0,7,2)}' input.txt
For awk, why substr when you have printf??
awk 'NF{printf("%.4s.%.2d.%.2d\n", $1, $1%10000/100, $1%100)}'