[英]How to populate records based on the string availability inside file in Linux
i am not expert in Linux commands, seeking all your help for my requirement.我不是 Linux 命令的专家,为我的要求寻求您的所有帮助。
i have file that has huge number of records, that we can be differentiated by three sections that is header record, Content and footer records.我有一个包含大量记录的文件,我们可以通过三个部分来区分,即 header 记录、内容和页脚记录。
File Sample Content:-文件样本内容:-
HDR1
HDR2
HDR3
LIN+1
bla blaa1
Bla blaa2
......
.....
..
LIN+2
bla blaa1
Bla blaa2
......
.....
..
Footer1
Footer2
Footer3
From the above sample records from a file, I want to populate the Lines from "LIN+2" to before "Footer1" line to another new file and delete the lines from the old file.从文件中的上述示例记录中,我想将“LIN+2”行到“Footer1”行之前的行填充到另一个新文件中,并从旧文件中删除这些行。
Please help with the command, your help will be much appreciated.请帮助使用命令,非常感谢您的帮助。
I won't give you the entire solution, but using these tips you can find out:我不会为您提供完整的解决方案,但使用这些提示您可以找到:
grep
(like grep "LIN+2" filename)
.grep
(如grep "LIN+2" filename)
。-n
to the result in order to know the line number of the result (like grep -n "LIN+2" filename
).-n
以了解结果的行号(如grep -n "LIN+2" filename
)。awk
, you can make sure only to get that information (like grep "LIN+2" filename | awk -F: '{print $1}'
).awk
,您可以确保只获取该信息(如grep "LIN+2" filename | awk -F: '{print $1}'
)。head -n 10 filename
.head -n 10 filename
。tail -n 10 filename
.tail -n 10 filename
。 Using that information, you should be able to get your result.使用该信息,您应该能够获得结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.