Reputation: 65
How to extract file content from match pattern to another match pattern. Not just split.
For example:
1.txt
myname
myage
myeducation
myaddress
> myoccupation
mydesignation
mysalary
myofficename
> mygrosssalary
mypermanentaddress
myfathersname
in above file i want to extract content to another file and remove content starting from pattern
> myoccupation
to
> mygrosssalary
to another file.
Upvotes: 1
Views: 137
Reputation: 58420
This might work for you (GNU sed):
sed -i -e '/> myoccupation/,/> mygrosssalary/{w newfile' -e 'd}' file
Upvotes: 3
Reputation: 33327
With awk:
awk '/> myoccupation/,/> mygrosssalary/' file
With sed:
sed -n '/> myoccupation/,/> mygrosssalary/p' file
And you can use output redirection to create another file, with
comand ... > newfile
Upvotes: 3