我是unix shell脚本的新手。我的目标是提取“--------”行之间的一组字符串,并将每组字符串存储到不同的文件中。
例如: 我的文件main.txt看起来像
----------------------------
One
two
three
----------------------------
abc
four
five
-----------------------------
预期产出: 出现在“----”行之间的字符串必须存储在不同的文件中,如
first.txt contains,
one
two
three
Second.txt contains,
abc
four
five
请求您提供宝贵的帮助。
提前致谢, SRIKANTH
答案 0 :(得分:1)
i=0; file=$i.txt; cat tmp/t.txt |while read line;
do if [ "$line" = "----------------------------" ];
then let "i=i+1"; file=$i.txt; continue;
fi;
echo "$line" >> $file;
done
顺便说一下,我只使用shell进行交互式工作。所有编码都在Python中完成。
你也可以使用awk。但是你也可以使用Python,Ruby等....