Reputation: 141
I have a file which looks like this (myfile.txt):
{"total":25,"p":1,"ps":100,"paging":{"pageIndex":1,"pageSize":100,"total":25},"issues":[{Lorem Ipsum is simply dummy text of},
{the printing and typesetting industry. Lorem Ipsum has been the industry's},
{standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a},
{type specimen book.}
I want to cut these text:
{"total":25,"p":1,"ps":100,"paging":{"pageIndex":1,"pageSize":100,"total":25},"issues":[
I may use 2 methods here (any method is possible).
{"total"
and end with "issues":[
(( including {"total"
and "issues":["
))"issues":[
text ((including "issues":[
))then output would be
{Lorem Ipsum is simply dummy text of},
{the printing and typesetting industry. Lorem Ipsum has been the industry's},
{standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a}
{type specimen book.}
I tried this
cat myfile.txt | sed 's/{"total"//g' | sed 's/"issues":[//g'
but it occurs errors.
Can someone help me to figure out this?
Upvotes: 1
Views: 255
Reputation: 11237
Using sed
$ sed 's/^{"total[^[]*\[//' input_file
{Lorem Ipsum is simply dummy text of},
{the printing and typesetting industry. Lorem Ipsum has been the industry's},
{standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a},
{type specimen book.}
Upvotes: 1
Reputation: 8621
You can use operator s///
of sed for this:
sed -i 's/{"total.*issues":\[\(.*\)/\1/' t.txt
{"total
: pattern starts with that.*
: anything between the beginning and end of patternissues":\[
: the end of the pattern\(.*\)
: everything else in the rest of the line\1
: replaced by the content between parenthesisUpvotes: 0