3

I have copy-pasted the JSON structure into a .txt file for my input file (I will have a number of these).

I'm looking for the "Name" text between "start" and "end", my input file is large and the parts I want to extract from look like this:

Here: "start",
        title: "Name",
        type: "end",
        words: "more words",

I've tried the following but it doesn't work.

input.txt < sed -n '/^start",$/,/^type: "end"$/p' data > output.txt

Thank you.

1

2 Answers 2

1

data.txt

...
Here: "start",
        title: "Name",
        type: "end",
        words: "more words",
...

Sed command:

 $ sed -n '/start",$/,/ *type: "end",$/p' data.txt

Output:

Here: "start",
        title: "Name",
        type: "end",

^ won't match the start line since there's a "Here:" before it and "end"$ won't match the end line since there's a comman after the last quotation mark.

Sign up to request clarification or add additional context in comments.

Comments

0

With the sample input you posted this is all you need:

$ awk -F\" '/end/{print t} {t=$2}' file
Name

If that's not adequate then come up with more truly representative sample input that includes the cases you think will be difficult for a script to deal with. It's always trivial to extract the text you want and MUCH harder to not extract text you don't want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.