LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 04:10 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129

Rep: Reputation: 17
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, 04:27 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 04:35 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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, 04:38 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

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

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 06:17 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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, 08:27 AM   #7
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129

Original Poster
Rep: Reputation: 17
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, 08:30 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

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


Reply



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

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

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

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
Open Source Consulting | Domain Registration