i am not expert in Linux commands , seeking all your help for my requirement.
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 .
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 .
Please help with the command , your help will be much appreciated .
CodePudding user response:
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
(likegrep "LIN 2" filename)
. - Once you have this, you can add
-n
to the result in order to know the line number of the result (likegrep -n "LIN 2" filename
). - Using
awk
, you can make sure only to get that information (likegrep "LIN 2" filename | awk -F: '{print $1}'
). - In order to see the first 10 lines of a file, do
head -n 10 filename
. - In order to see the last 10 lines of a file, do
tail -n 10 filename
.
Using that information, you should be able to get your result.