我與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
您可以從輸入文件添加示例數據嗎? – Alex 2013-02-27 19:06:29
可怕的格式!不要添加非答案作爲答案更新問題。你真的**需要閱讀[FAQ](http://stackoverflow.com/faq) – 2013-03-01 11:23:52