【发布时间】:2012-08-04 06:49:58
【问题描述】:
我有一个小问题。我需要根据文件的某些起始字符串对文件进行排序。例如按照数字 04、05 或 06 的这种形式:
04..............
................
................
05..............
................
................
06..............
................
................ etc..
这是我的 awk 代码:http://pastebin.com/dLsWkV3q
或者就在这里:
echo "starting...input file"
read file
echo "reading file..."
echo "... now sorting..."
cat $file | awk '{
if($1=="04"){
print >> "04_file.txt";
}
if($1=="05"){
print >> "05_file.txt";
}
if($1=="06"){
print >> "06_file.txt";
}
}'
echo "finished, bye?"
read wait
echo "bye"
目标是我需要多个仅包含相应块的文件,例如上面的示例:结果我将有 3 个文件。 04_file.txt、05_file.txt 和 06_file.txt。并且05_file.txt 没有来自 04 块的任何行。最终的04_file.txt 文件将只有这个:
04..............
................
................
我的问题是它会将其他块也保存到 04_file.txt..
我将不胜感激。非常感谢
【问题讨论】:
-
看起来你可以用
csplit做到这一点?