LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2017, 07:36 AM   #1
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Rep: Reputation: Disabled
sed/awk - delete special character from a file


How could I remove backslash special character from a file with sed/awk?

input:
Code:
$P$DuOxmeTb7uGqNkkzenh6BqBu5OmpDF\/
$P$DPUN9ULZv9ICq.o53w4Kk\/685Q7mdW0
$P$DbHTs7pYRbB4s5sHzXh\/JK7kFa4SIT0
output:
Code:
$P$DuOxmeTb7uGqNkkzenh6BqBu5OmpDF/
$P$DPUN9ULZv9ICq.o53w4Kk/685Q7mdW0
$P$DbHTs7pYRbB4s5sHzXh/JK7kFa4SIT0
tried with "tr", it works:
Code:
tr -d "\\" <file | less
with "sed" I got error message:
Code:
sed -E 's/.*(\/).*/\/g' file | less

Last edited by freeroute; 09-25-2017 at 07:46 AM.
 
Old 09-25-2017, 07:53 AM   #2
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
I found the solution:
Code:
sed -E 's/\\\//\//g' file | less
 
Old 09-25-2017, 08:54 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,764

Rep: Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050Reputation: 3050
Why not sue the same code from tr in sed? Your first sed is in no way anything the same and your second seems to require additional information.
Code:
sed -E 's/\\//g' file
 
1 members found this post helpful.
Old 09-25-2017, 09:15 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,506

Rep: Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314Reputation: 4314
using sed you may try another delimiter:
Code:
sed -E 's!\\/!/!g' file | less
that will be much more readable
 
2 members found this post helpful.
Old 09-25-2017, 09:32 AM   #5
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thanks. Yes the delimiter was forward slash, and it was hard to read the code...
 
Old 10-19-2017, 04:35 AM   #6
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
I try to delete the escape character using awk. (deleting with sed or tr works)
Command:
Code:
awk '{gsub ("\\", ""); print $0}' file
or
Code:
awk '{gsub ("'\'", ""); print $0}' file
Not working (substitute backslash with nothing). Why?

Last edited by freeroute; 10-19-2017 at 04:36 AM.
 
Old 10-19-2017, 06:09 AM   #7
freeroute
Member
 
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69

Original Poster
Rep: Reputation: Disabled
Solution: awk '{gsub(/\\/, ""); print}' file.txt

Regex must be between forward slashes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk - special character as delimiter freeroute Linux - Newbie 7 09-15-2017 02:27 PM
sed command to replace special character in special line rubylu Linux - Newbie 3 04-09-2015 02:45 PM
[SOLVED] sed or awk delete LF terminated lines from file Z038 Programming 3 12-21-2013 01:07 AM
sed/awk: Three consecutive blank lines in a file, how to delete two of them? recomboDNA Programming 8 06-17-2010 10:50 AM
how to delete duplicates entries in xml file using sed/awk/sort ? catzilla Linux - Software 1 10-28-2005 03:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration