LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 11-01-2013, 08:45 AM   #1
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 113

Rep: Reputation: 15
bash scripting issue...


Hi all,
I have a file with the the following multiple entries:

file://csb1/abc/123/1
file://tom1/abc/123/2
file://mason1/zyx/987/3

Now I need to replace the text in file://csb1 to file://server3 and without modifying the rest of the UNC path. This has to be done on all UNC paths so the results would be:

file://server3/abc/123/1
file://server3/abc/123/2
file://server3/zyx/987/3

This is in a bash script. Please help! Thanks.
 
Old 11-01-2013, 09:28 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Would this help:
Code:
sed 's%//[[:alnum:]]*/%//server3/%' infile
Example:
Code:
$ cat infile 
file://csb1/abc/123/1
file://tom1/abc/123/2
file://mason1/zyx/987/3

$ sed 's%//[[:alnum:]]*/%//server3/%' infile 
file://server3/abc/123/1
file://server3/abc/123/2
file://server3/zyx/987/3
 
1 members found this post helpful.
Old 11-01-2013, 10:34 AM   #3
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 113

Original Poster
Rep: Reputation: 15
Thanks Druuna!!!

But can you walk me though what the command is doing? I'm a newbie with sed.
 
Old 11-01-2013, 10:37 AM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
He is saying:

replace anything between // and / that is alphanumeric of any length with server3. Which is what you asked for.
 
Old 11-01-2013, 11:10 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by L1nuxn00b703 View Post
Thanks Druuna!!!
You're welcome.

Quote:
But can you walk me though what the command is doing? I'm a newbie with sed.
Out of the box sed uses forward slashes (/) to separate the search part and the replace part: sed '/foo/bar/'. But sed can use any separator you want. I used % because this way you don't have to escape the forward slashes in your lines.

Sed is greedy by nature, so this will not work:sed 's%//.*/%//server3/%' infile, you'll need to narrow down the search pattern. [:alnum:] is short for: [A-Za-z0-9] and will make sure that only the part betwee // and the first / after that is targeted.

These sed related links might help in the future:
- sed, a stream editor
- An Introduction and Tutorial
- sed & awk

BTW: Can you put up the [SOLVED] tag.
- above the first post -> Please Mark this thread as solved if you feel a solution has been provided.
- -or- -
- first post -> Thread Tools -> Mark this thread as solved

Last edited by druuna; 11-01-2013 at 11:12 AM.
 
Old 11-01-2013, 03:18 PM   #6
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 113

Original Poster
Rep: Reputation: 15
thanks alot!!! You guyz rock!
 
  


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
Expect/bash scripting issue ShadowAce Programming 3 01-05-2012 11:54 AM
[SOLVED] bash scripting question root cron issue mindcontrolusa Linux - General 5 12-02-2010 09:57 AM
[SOLVED] Bash scripting issue tubaboy Linux - Newbie 5 11-15-2010 08:41 AM
bash scripting issue thesav Programming 7 06-20-2009 03:38 AM
Looping issue in bash scripting ZAMO Linux - General 4 09-26-2008 12:22 PM


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