简体   繁体   English

如何根据 Linux 中文件内的字符串可用性填充记录

[英]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:我不会为您提供完整的解决方案,但使用这些提示您可以找到:

  • In order to find an entry in a file, you can use grep (like grep "LIN+2" filename) .为了在文件中查找条目,您可以使用grep (如grep "LIN+2" filename)
  • Once you have this, you can add -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 )。
  • Using 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}' )。
  • In order to see the first 10 lines of a file, do head -n 10 filename .要查看文件的前 10 行,请执行head -n 10 filename
  • In order to see the last 10 lines of a file, do tail -n 10 filename .要查看文件的最后 10 行,请执行tail -n 10 filename

Using that information, you should be able to get your result.使用该信息,您应该能够获得结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM