How to delete lines containing backslash \
Let's consider file foo.txt as below:
foo
bar
sna\fu
baz
Any of below commands would remove lines with \
:
grep -v '\\' foo.txt
sed -ne '/\\/ d; p' foo.txt
Remove backslashes with sed command in a file
Replaces sequences of 4 backslashes with 2 backslashes:
sed 's/\\\\\\\\/\\\\/g' input.txt
Alternatively, use {4}
to indicate how many \
are matched:
sed 's/\\\{4\}/\\\\/g' input.txt
input.txt
'AAA' 'a\\\\b\\\\a\\'
'BBB' 'q\\l\\s\\'
output
'AAA' 'a\\b\\a\\'
'BBB' 'q\\l\\s\\'
You must escape special regex characters like \
with another \
.
{
and }
are also regex characters, however the ed-like tools (ed,vim,sed,...) don't recognize them as such by default. To use curly-braces to specify a regex count (e.g., {4}
), sed requires you escape them (e.g., \{4\}
)
So...
- escape
\
to use it literally; not as a regex character - escape
{
and}
to use them as regex characters rather than literal braces
remove backslash only from quote character using sed
Your command is almost correct. You just forgot to substitute with a double quote:
sed -i 's/\\"/"/g' file.txt
sed
's s
command substitutes the first part (between /
here) with the second part. The g
flag repeats the operation throughout the line. Your mistake was that the second part was empty, thus effectively deleting the whole \"
string.
BTW, escaping the double quote is not necessary since your sed
command is inside single quotes.
Delete files with double quotes in their names
If you want to delete the files containing double quotes ""
, you can do this.
find . -type f -name '*"*"*.svg' -exec rm -f -- {} +
Edit: You need to first go to your file path and then execute above command.
cd /media/bruno/HDD Externo/temp/
How do I use sed to remove a double backslash
You can choose another delimiter than /
in your command:
sed 's;^//;;' file
Or, if you want to escape the /
:
sed 's/^\/\///' file
Related Topics
Update Specific Field in Text File in Specific Line
Linux Kernel: Copy_From_User - Struct with Pointers
Why Ln -Sf Does Not Overwrite Existing Link to Directory
Serialport in Mono in Linux Not Responding to Datareceived Event
How to Make My .Bat File Run Linux Command to Remote Linux
Sort Command in Not Working Properly in Unix for Sorting a CSV File
Find Files with a Certain Extension That Exceeds a Certain File Size
Linux: Differencebetween These Two Symbolic Link Commands
Diff (Gnu Diffutils) 3.6 Exclude Directory
Compute Base64 Encoded Hash from a Given Hash
How to Get the Exit Status of the First Command in a Pipe
/Var/Log/Daemon.Log Taking More Space How to Reduce It
Is Ethernet Checksum Exposed via Af_Packet
Delete Folder That Contain Subfolders and Files on Linux
Bash Shell: Cannot Use Variable $ as a Path to Run Tar
Screen Command Disable the Control Key Ctrl-A to Use It in Vim
How to Automate Measuring of Bandwidth Usage Between Two Hosts