user2692634
user2692634

Reputation: 65

extract file content from match pattern to another match pattern

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

Answers (2)

potong
potong

Reputation: 58420

This might work for you (GNU sed):

sed -i -e '/> myoccupation/,/> mygrosssalary/{w newfile' -e 'd}' file

Upvotes: 3

user000001
user000001

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

Related Questions