我有个一个文本处理的文件内容如下:
0205032354@ -35.0000@108.0010@76.0006@12@0.0
现在需要将他们处理成如下格式:
@2@5@3@23@54@@-35.000@@108.001@@@76.001@@@12@@@0.0
其中@代表一个空格
换一种说法就是所:把原文件中的每字段放到固定的位置上去。这里0205032354代表02年05月03日23时54秒(即把0改成空格)然后在此之后-35.0000通过四舍五入取小数点后三为-35.000接着就填入到一个9个字符位置中去即@@-35.000同理108.0010也成为@@108.001和76.0006成为@@@76.001而12则填入随后的一个5个字符的位置,0.0填入一个6个字符的位置。
请问高手们要怎么弄阿??
[问题]谁来帮帮我阿,我郁闷了好多天了!
-
- 帖子: 45
- 注册时间: 2008-03-22 1:19
- 联系:
-
- 帖子: 1
- 注册时间: 2008-05-16 22:35
#!/bin/ksh
file="odlfile"
cat odlfile | read time date1 date2 date3 date4 date5
echo $time | cut -c1-2 | read year
if [ $year -lt 10 ]
then
echo $year | cut -c2 | read year
fi
echo $time | cut -c3-4 | read month
if [ $month -lt 10 ]
then
echo $month | cut -c2 | read month
fi
echo $time | cut -c5-6 | read date
if [ $date -lt 10 ]
then
echo $date | cut -c2 | read date
fi
echo $time | cut -c7- | read minu
echo $date1 | cut -d. -f1 | read date1head
echo $date1 | cut -d. -f2 | read date1queur
echo $datequeur | cut -c1-3 | read queur11
echo $datequeur | cut -c4 | read queur12
date1cal=${date1head}$queur11
if [ $queur12 -ge 5 ]
then
adder=1
else
adder=0
fi
date1=$((date1cal+adder))
echo $date1 | wc -c | read num
num=$((num-3))
echo $date1 | cut -c$num- | read date1queur
echo $date1 | cut -c1-$num | read date1head
date1=${date1head}'.'$date1queur
# you can tread the rest with same way
printf printf "%2s%2s%s2%s%9s%9s%9s%5s%6s" $year $month $date $time $date1 $date2 $date3 $date4 $date5 > newfile
sorry I have not so such time to finish it and i think you can work well then me
file="odlfile"
cat odlfile | read time date1 date2 date3 date4 date5
echo $time | cut -c1-2 | read year
if [ $year -lt 10 ]
then
echo $year | cut -c2 | read year
fi
echo $time | cut -c3-4 | read month
if [ $month -lt 10 ]
then
echo $month | cut -c2 | read month
fi
echo $time | cut -c5-6 | read date
if [ $date -lt 10 ]
then
echo $date | cut -c2 | read date
fi
echo $time | cut -c7- | read minu
echo $date1 | cut -d. -f1 | read date1head
echo $date1 | cut -d. -f2 | read date1queur
echo $datequeur | cut -c1-3 | read queur11
echo $datequeur | cut -c4 | read queur12
date1cal=${date1head}$queur11
if [ $queur12 -ge 5 ]
then
adder=1
else
adder=0
fi
date1=$((date1cal+adder))
echo $date1 | wc -c | read num
num=$((num-3))
echo $date1 | cut -c$num- | read date1queur
echo $date1 | cut -c1-$num | read date1head
date1=${date1head}'.'$date1queur
# you can tread the rest with same way
printf printf "%2s%2s%s2%s%9s%9s%9s%5s%6s" $year $month $date $time $date1 $date2 $date3 $date4 $date5 > newfile
sorry I have not so such time to finish it and i think you can work well then me
- laborer
- 帖子: 1016
- 注册时间: 2005-10-25 11:15
- 联系:
输入:
结果:
代码: 全选
echo "0205032354 -35.0000 108.0010 76.0006 12 0.0" | awk '{ for (i=1;i<10;i+=2) system("printf \" %d\" "substr($1,i,2)); system("printf \"%9.3f%9.3f%9.3f%5d%6.1f\" "$2" "$3" "$4" "$5" "$6) }'
代码: 全选
2 5 3 23 54 -35.000 108.001 76.001 12 0.0
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser