LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-08-2004, 01:01 AM   #1
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Rep: Reputation: 30
sed question


Hi folks. This is one of them simple questions. I'm not getting many good results on the search engines and I have spent a lot of time trying to find a "reminder" how to do this.

I have over 30 files which were made using MS Front Page. All the files are pathed in MS-DOS format. I run a web server under Linux RH9. I need to convert the DOS path of each and every file to a Linux Path. There's just to many to do this stuff without using sed. Could someone give me an example so I can recall how I did this.

Code:
Say my MS-DOS path is:
C:\webpage\image\file.gif

Say my desired Linux path is:
http://website/image/file.gif
Thanks a bunch!
 
Old 03-08-2004, 01:33 AM   #2
the_tflk
Member
 
Registered: Jul 2003
Location: MA
Distribution: Ubuntu
Posts: 35

Rep: Reputation: 16
Lightbulb

well, I know it's not the answer you were looking for, but here is an easy way to do it for multiple files despite having to do it by hand for each.
vi can do this very easily.

vi filename.htm
%s#C:\\#http://yournameinlights/# *not sure if you have to escape the colon...*
%s#\\#/#
:wq

- fin, mais

if you feel really impatient you could...
$ wc -l *.htm *for the line numbers*
cat all the files into one, run this on the whole file at once and then head -n | tail -n > filename2.htm the correct number of lines for each out of the main one....

$ wc -l *.htm

if you dont know how to do something with a command then you should look at the man pages for it.
best of luck.

Last edited by the_tflk; 03-08-2004 at 01:44 AM.
 
Old 03-08-2004, 04:12 AM   #3
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
FYI:
Code:
Step 1:
%s#E:\\#\#

Step 2:
%s#\\#\#

Step 3:
Repeat step 2 until all "\" were replaced with "/"

Step 4:
%s#/directory/directory/directory#http://websitepath

Step 5:
Save file
This process saved me over 300 lines of manual coding. Thank you very much.

Though I firmly believe sed would have been much better, since no reply came in and 30 minutes of my time was spent trying to get sed to work with non-alphanumeric characters, I am up-most grateful.

Your suggestion regarding the wc -l, 1 step substitution process seemed most admirable but also very dangerous. I am thankful I did a test before actually using the process on the original files. The reason why was because after concluding the process, I debugged a +1 line on the wc -l. If I had used the head | tail command, I would have had to debug all those files to find that one (and perhaps multiple) lines of invalid data.

I believe it would have been safer to just use tail to appended a <!-- EOF --> message on all files. Then following the process by merging them using cat > filename. Never-the-less, it would still have been dangerous and I was to much in the need to get this all done.

Again, thanks for your help. Job complete.
 
Old 03-08-2004, 11:56 PM   #4
the_tflk
Member
 
Registered: Jul 2003
Location: MA
Distribution: Ubuntu
Posts: 35

Rep: Reputation: 16
Glad to help... I have only been using linux as a dedicated user for a short time - thanks for the heads up, I dont usually post, I just come here to solve my problems! :-D ...I have been installing and abandoning mandrake and red hat for years....
What did you mean about the tailing something into a file?
I know I still have some more tricks to learn.
Again, glad to help.
 
Old 03-09-2004, 10:27 AM   #5
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
"Step 3:
Repeat step 2 until all "\" were replaced with "/" "

Put a "g" on the end of the command and it will do them all at once:

:%s#\\#/#g


"Though I firmly believe sed would have been much better, since no reply came in and 30 minutes..."

The syntax for sed is about the same (for next time):

cat file | sed 's#\\#/#g'
 
  


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
sed question ckoniecny Linux - General 3 11-11-2005 10:31 AM
question on sed tifu Linux - Newbie 3 03-18-2005 05:38 PM
sed question virendratp Programming 3 09-10-2004 04:21 AM
little sed question freelinuxcpp Linux - Software 3 01-20-2004 08:36 AM
sed question zoomzoom Linux - Software 2 10-20-2003 05:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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