LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-13-2010, 05:10 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Rep: Reputation: 16
modify a file that contains \\ using sed or awk


I need to modify a file that contains \\tsus.fbfs.com\appsdata\StormLoss\Production\ and replace the \\tsus.fbfs.com\appsdata\StormLoss\Production\ line with rm -f /mnt/nfsvol/PC/SLR/

I have tried:

sudo find /home/appadmin/ -name sql.out -execdir sed -i 's#\\tsus.fbfs.com\appsdata\StormLoss\Production\#"rm -f /mnt/nfsvol/PC/SLR/"#' {} \;

but it provides an error on the second \. I need to change this in place and not redirect to another file.

Is this possible? I have used sed and awk before but not extensively.

Thank you!
 
Old 05-13-2010, 05:27 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Eeekkkk, gag, yuck!!!

You have "DOS-slashes"---Real men use "Unix-slashes"...... (I can never remember which is forward and which is back.....)

In regular expressions and many other places, "\" is the "escape" character. To use it literally, you need to---you guessed it---ESCAPE it!!

Typically, "\\" means a literal "\"

This illustrates the point (I created the file "esc" for the purpose):
Code:
[mherring@mystical play]$ more esc
\abvc
\\aegasd
adsg\\asdg
asdgf\
asdg\\\
[mherring@mystical play]$ grep '\\' esc
\abvc
\\aegasd
adsg\\asdg
asdgf\
asdg\\\
[mherring@mystical play]$ grep '\\\\' esc
\\aegasd
adsg\\asdg
asdg\\\
[mherring@mystical play]$ grep '\\\\\\' esc
asdg\\\
What I'm stuck on is that I cannot seem to use the same approach in SED....
 
Old 05-13-2010, 05:35 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,242

Rep: Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408Reputation: 1408
Quote:
Originally Posted by pixellany View Post
What I'm stuck on is that I cannot seem to use the same approach in SED....
Works fine here, just double up the slashes:
Code:
~/src$ echo '\\tsus.fbfs.com\appsdata\StormLoss\Production\' | sed 's#\\\\tsus.fbfs.com\\appsdata\\StormLoss\\Production\\#rm -f /mnt/nfsvol/PC/SLR/#'
rm -f /mnt/nfsvol/PC/SLR/
 
Old 05-13-2010, 05:38 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
My mistake!!---I was using the wrong SED syntax
 
Old 05-14-2010, 02:22 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by pixellany View Post
(I can never remember which is forward and which is back.....)
Try this as an aide-memoire: the conventional direction of writing is left to right and the conventional direction of progress (forward, back) is down to up.
 
Old 05-14-2010, 07:17 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Ah yes!!

Linux is forward, Windows is backward

In Linux we use \ to escape (from Windows)


And remember that Unix came first---when DOS arrived, they had to have a new look.
 
Old 05-14-2010, 09:27 AM   #7
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
modify a file that contains \\ using sed or awk

okay, we got it figured out. thank you for the replies and the explanation of forward/back slash.

We just needed to double the '\' in each instance and it worked.

sudo find /home/appadmin/ -name sql.out -execdir sed -i 's#\\\\tsus.fbfs.com\\appsdata\\StormLoss\\Production\\#"rm -f /mnt/nfsvol/PC/SLR/"#' {} \;
 
Old 05-14-2010, 09:30 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
If it works now, mark the thread as Solved (in Thread Tools).
 
  


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
Using sed or awk to filter a file mitchell2345 Linux - Software 3 04-10-2009 11:07 AM
Manipulating Text File with awk or sed kushalkoolwal Programming 2 09-10-2008 08:35 PM
Modify a text files with awk/sed/perl climber75 Programming 15 08-05-2008 04:35 PM
mass file renaming sed/awk/mv asalford Linux - General 2 01-16-2008 06:53 PM
How exclude | from txt.file using awk or sed? sarajevo Programming 2 08-21-2006 08:26 AM

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

All times are GMT -5. The time now is 12:00 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