Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-29-2009, 09:13 AM   #1
LQ Newbie
Registered: Aug 2009
Posts: 22

Rep: Reputation: 15
Question sed backslash question

I am trying to write a reporting script for my apache logs. Some of the referer URLs in my logs have backslashes in them, and my code can't figure out what to do with them, so it just errors out. I want to replace all '\' characters with '\\', and I can't get it to work. If I run this from the command line:

echo "\xb4\xf3\xcd\xe6\xd0\xa6+%B9%F9%BE%B2&clz=" | sed -e 's#\\#\\\\#g'

I get this output:

But if I run it from within my script:

for i in `cat apache.log | sed -e 's#\\#\\\\#g' `; do

I get this error: "sed: -e expression #1, char 8: unterminated `s' command", and my strings are not changed. I have no idea why this isn't working...
Old 09-29-2009, 09:47 AM   #2
LQ Newbie
Registered: Aug 2009
Posts: 22

Original Poster
Rep: Reputation: 15
I figured this out just by shooting in the dark. I know the '\' character has to be escaped, so I just tried various iterations until I got it. Here is the proper code:

for i in `cat apache.log | sed -e 's#\\\#\\\\\\\#g' `; do # first 3 '\'s, and then 7 '\'s


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
sed command to replace slash with backslash stelmed Slackware 13 08-19-2010 05:01 AM
converting Dos link backslash to Unix like backslash barunparichha Linux - Software 1 05-14-2009 09:54 AM
sed question unihiekka Linux - Newbie 5 12-11-2008 01:54 AM
backslash in vi ashlesha Linux - Newbie 5 02-24-2007 06:27 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:47 PM.

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