sed to remove single and double quotes at the same time

后端 未结 7 2233
忘了有多久
忘了有多久 2020-12-28 20:38

I am trying to remove single quotes and double quotes from a file. Can I do it in a single sed command?

I am trying :

sed \'s/\\\"//g;s/\\\'//g\' tx         


        
相关标签:
7条回答
  • 2020-12-28 21:12

    To remove single quotes, simply use double quotes for the regex in sed:

    sed -e "s/'//g" ./new_file.csv

    0 讨论(0)
  • 2020-12-28 21:14

    Another possibility would be to use tr:

    tr -d \'\" file
    
    0 讨论(0)
  • 2020-12-28 21:16

    I solved it (in Centos 7) by removing surrounding quotes all together like:

    sed -i s/\'//g file;sed -i s/\"//g file 
    
    0 讨论(0)
  • 2020-12-28 21:19

    You can use commands below

    sed "s/'/ /g" file.txt > newfile.txt
    sed 's/\"//g' newfile.txt > Required_file.txt
    

    Required_file.txt is the final output.

    0 讨论(0)
  • 2020-12-28 21:27

    You cannot escape a single quote inside a pair of singe quotes in shell. Escaping double quotes is allowed though. Following sed command should work:

    sed "s/['\"]//g" file
    
    0 讨论(0)
  • 2020-12-28 21:33

    Try this one instead :

    sed -e 's|["'\'']||g' txt
    
    0 讨论(0)
提交回复
热议问题