我需要在最后一行添加换行符和{在文本文件的每5行和}。 [英] I need to add a newline and a { at every 5th line of a text file and a } at the last line.
本文介绍了我需要在最后一行添加换行符和{在文本文件的每5行和}。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际文件内容:
Actual File Content :
FORMAT_VERSION:01.03
FILE_DATE:20180123171011
FILE_ID:01231711
CCBSFormatVersion(03.00)
FileData(ABCD,4)
UpdateSubscription(*******000*****,IMSI)
{
DestinationAddress()
}
RemoveSubscriptionFromGroup(***************,IMSI,"Prepaid")
我需要以下格式:
I need the below format:
FORMAT_VERSION:01.03
FILE_DATE:20180123171011
FILE_ID:01231711
CCBSFormatVersion(03.00)
FileData(ABCD,4)
{
UpdateSubscription(*******000*****,IMSI)
{
DestinationAddress()
}
RemoveSubscriptionFromGroup(***************,IMSI,"Prepaid")
}
我的尝试:
我尝试过各种各样的选择。请帮助我使用基于UNIX的命令。
What I have tried:
I have tried sed with various options. Please help me with UNIX based command.
推荐答案
awk '//{if (n==4) print("{"); print(
0); ++ n} END {printf(} \ n);}'< filename>
0);++n}END{printf("}\n");}' <filename>
(其中< filename>
是原始文件的名称)
可以解决问题。
(where <filename>
is the name of the original file)
would do the trick.
解决方案:
do
sed -i'5a {'
Solution :
do
sed -i '5a {'
这篇关于我需要在最后一行添加换行符和{在文本文件的每5行和}。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文