LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   sed question (https://www.linuxquestions.org/questions/linux-software-2/sed-question-154840/)

dolvmin 03-08-2004 12:01 AM

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!

the_tflk 03-08-2004 12:33 AM

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.

dolvmin 03-08-2004 03:12 AM

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. :p

the_tflk 03-08-2004 10:56 PM

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.

mfeat 03-09-2004 09:27 AM

"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'


All times are GMT -5. The time now is 03:01 PM.