skip to Main Content

I am having json file containing multiple "t" in it, I want to remove these characters from json file as when I am trying to convert this json file into CSV, because of these characters my CSV output disturbing.

I have tried multiple times with trial and error methods.

sed -i 's/t//g' input.json

Then I tried;

sed -i 's/^t//g' input.json

And then;

sed -i 's~t~~g' input.json

But unable to remove this "t" character from input.json file.

2

Answers


  1. Backslash is special in sed regular expressions. To match it literally, you need to escape it by preceding it by another backslash.

    echo 'atb' | sed 's/\t//g'
    ab
    
    Login or Signup to reply.
  2. To remove the backslash and "t" from a file, you can use the sed command in Linux:

    sed 's/\t//g' input.json
    

    Maybe, it’s better to use a JSON parser like jq to modify JSON files instead of using sed:

    jq 'gsub("\t";"")' input.json
    

    Note: You can use the -i option in both commands to edit the file in place.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search