我有一个包含 2 月 1 个月数据的文件,我需要每天拆分Feb
文件,即将文件拆分为Feb_1
, Feb_2
... Feb_29
。
这是我的逻辑:
Inputfile= $1
monthname = "Feb"
while getopts :
datefield="1"
outfile="Feb_1"
while read line
do
s = `echo "$line" | awk '{print $2}'`
t = `echo "$line" | awk '{print $3}'`
if [ "$s" = "$monthname" ]
if [ "$t" = "$datefield" ]
echo $line > "$outfile"
else
datefield = $t
outfile =$monthaname"_"$t
echo $line > "$outfile"
fi
else
echo $line > "$outfile"
fi
done < "$inputfile"
但s = echo "$line" | awk '{print $2}'
这并没有给我第二个词,因为我正在使用$2
它要求第二个命令行参数。我试过把'
之前放$2
如下。
s = echo "$line" | awk '{print '$2}'
在这种情况下,它会抛出一个新错误,假设第一行是Wed Feb 1
它的抛出错误,因为Wed Feb 1
它不存在。
这是示例数据:
Wed Feb 1 00:10:00 cpu usage
KLOGENT.exe 3068 SYSTEM 00 0:00:00 17345K 15467 BELOW NORMAL
SGHT.exe 3868 SYSTEM 00 0:00:00 18845K 15499 BELOW NORMAL
.......
.......
Wed Feb 1 00:15:00 cpu usage
KLTREENT.exe 3068 SYSTEM 00 0:00:00 17345K 15767 BELOW NORMAL
KJTRT.exe 3868 SYSTEM 00 0:00:00 18845K 13699 BELOW NORMAL
..............
...........
Wed Feb 1 23:55:00 cpu usage
HTR.exe 3068 SYSTEM 00 0:00:00 1785K 4532 BELOW NORMAL
KLU.exe 3868 SYSTEM 00 0:00:00 15645K 678 BELOW NORMAL
...............
.................
Thu Feb 2 00:10:00 cpu usage
JUYT.exe 3068 SYSTEM 00 0:00:00 143245K 157767 BELOW NORMAL
GFD.exe 3868 SYSTEM 00 0:00:00 18845K 879 BELOW NORMAL
.........................
.......................
Thu Feb 28 00:15:00 cpu usage
FRE.exe 3068 SYSTEM 00 0:00:00 143245K 157767 BELOW NORMAL
YUT.exe 3868 SYSTEM 00 0:00:00 18845K 879 BELOW NORMAL
............................
...................
Thu Feb 28 23:55:00 cpu usage
TRE.exe 3068 SYSTEM 00 0:00:00 143245K 157767 BELOW NORMAL
KJH.exe 3868 SYSTEM 00 0:00:00 18845K 879 BELOW NORMAL