我目前正在处理一个批次-50加csv文件,每周的时间戳显示为Tue Oct 01 10:59:59 PDT 2013.我需要能够通过逐行并将格式更改为10/01/13 10:59:59。一些文件有第一个字符串的时间戳,一些有第三个字符串。我没有运气...bash脚本在.csv文件中更改日期格式
这是一个csv文件的两个片段。
1.csv
Tue Oct 01 10:59:59 PDT 2013,data1,1,Databcd,Dataxyz,0,0,431,0
Tue Oct 01 11:59:59 PDT 2013,data1,1,Databcd,Dataxyz,0,0,401,0
2.csv
data1,0,Databcd,0,0,0,Tue Oct 01 11:59:59 PDT 2013,Dataxyz
data1,0,Databcd,0,0,0,Tue Oct 01 12:59:59 PDT 2013,Dataxyz
在此先感谢 -
这里是脚本,因为我最后一次运行它..
#!/bin/bash
for f in $*
do
echo "Processing [$f]..."
ftemp=$f.TMP
#echo "ftemp=$ftemp"
#this uses sed to delete the day(word) frm the timestamp.
sed -e 's/Mon //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed -e 's/Tue //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed -e 's/Wed //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed -e 's/Thu //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed -e 's/Fri //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed -e 's/Sat //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed -e 's/Sun //g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
#strip out the PDT & Year from end of each line
sed -e 's/\ PDT//g' -e 's/\ PST//g' <$f >$ftemp
mv $ftemp $f #copy it back over the original
sed --date="Oct 01 00:59:59 2013" +%D <$f >$ftemp
mv $ftemp $f #copy it back over the original
#echo "10/01/2013" | sed -E 's/([a-z ]?)\/([0-9][0-9 ]?)\/([0-9][0-9][0-9][0-9]
#/\3-\2-\1/' <$f >$ftemp
# tr 'Oct' '10/' <$f >$ftemp
# mv $ftemp $f #copy it back over the original
done
echo "Done."
正如你所看到的,我有我已经尝试注释掉
'我有没有运气...'。告诉我们你的尝试。 – devnull