文件A要把它拆成B和C两个文件,并且B和C的格式与A的格式一样。
例如:
A文件内有如下格式的数据,每行数据的字段用空格分割,每个字段固定长度。
0200 000000000001 11111 010 33
0200 000000000001 22222 010 33
0200 000000000001 22222 010 33
0200 000000000001 11111 010 33
要求:如何将第三个字段等于11111的一整行数据放到文件B内,将第三个字段等于22222的一整行数据放到文件C内。
[code="java"]
#!/bin/sh
FILE1=$1
if [ ! -e $FILE1 ]; then
echo "$FILE1 is not exsit"
fi
str=11111
str2=22222
touch b.txt
touch c.txt
#for i in cat $FILE1
;
cat $1 |while read line
do
echo $line
temps=echo $line |awk '{print $3}'
if [ $temps -eq $str ]; then
echo $line >> b.txt
fi
if [ $temps -eq $str2 ]; then
echo $line >> c.txt
fi
done
[/code]
有什么问题,追加评论