0

I want to remove block of text in file.

file

      .
      .
      .
 "chromedriver": {
      "version": "80.0.2",
      .
      .
      .
   }
     },
 "ci-env": {
      .
      .
      .

I want remove attribute chromedriver witch is define in multiple lines.

I tried this:

sed -i 's/"chromedriver"(\s|\n|.)*"ci-env":/"ci-env":/g' file

but it doesn't work. There is a oneliner that can resolve my problem? Is sed can do this?

1
  • 3
    is it a json file? can you show more content? anyway, when working with json, jq is much more better suited than sed, awk and other line oriented unix tools. Commented Aug 18, 2020 at 8:26

2 Answers 2

1

Using jq, which as mentioned in a comment is the better approach for dealing with JSON:

jq 'del(.chromedriver)' file > file.tmp && mv -f file.tmp file

(Guessing at the appropriate path here because your example data is way too sketchy)

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

Comments

0

Ed to the rescue!

#!/bin/sh

cat >> edcut.txt << EOF
/chromedriver/
ka
/ci-env/
-1
kb
'a,'bd
wq
EOF

ed -s file.json < edcut.txt

if you wanted to extract the record to another file, replace 'a,'bd with 'a,'bW newfile.txt.

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.