|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, I have a text file which is output from a server and it lists all the files in a specific volume. However, the volume name appears as volume_name:. I would like to replace this with \\volume_name\volume_name. This is not a problem in itself as I can use sed to globally look for the volume_name: pattern in the text file and replace it with the correct string. However, since there are many volume names in different text files and the process to replace them is exactly the same, I was thinking of a more generic solution. So at the moment the format goes like this: Code:
^volume_name:\folder_name\folder_name^ Is it possible to use sed to analyse the characters from between ^ and \ and then replace them with \\volume_name\volume_name minus the colon. The ^ sign is the delimiter in this file. Any suggestion most appreciated. Regards, vnayak |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Well, it seems almost the norm for sed type stuff, but maybe you have not been to vi/ex/sed school! Code:
sed '
s/^\([a-zA-Z0-9_]\{3,33\}\):/\\\\\1\\\1/
' in_file1 >out_file1If you have the gnu sed, you can use -i for update in place, but I would not: disk is cheap and mistakes are expensive, so make new files. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi DGPickett, Thanks for your prompt reply and for the code. However, when I try it does not do anything to the file I have. So I created a test document (in Pico!) which contained the following data: Code:
^server_name:\folder\folder name\ and the sed routine did not modify to \\server_name\server_name as I would have expected. Any ideas? Many thanks, vnayak Quote:
|
|
#4
|
|||
|
|||
|
Is the caret mark a literal in your file. I think we need more examples.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Yes. It is setup to be a delimiter. This file will be transferred to Excel at some stage and the caret is only sign that will allow other data in the file to be imported properly. So for example each line in the file is constructed like this: Code:
"OWNER^volume_name:\Volume_name^LONG^[Supervisor]^" "OWNER^volume_name:\Volume_name\folder^LONG^[Supervisor]^" I hope this make it a bit clearer. vnayak Quote:
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Case shift and all? volume_name Volume_name
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Hi DGPickett,
I am not sure what you mean. Would you mind re-explaining that? Thanks, vnayak |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed replacing specific characters and control characters by escaping | ijustneeda | Shell Programming and Scripting | 11 | 05-03-2012 03:40 PM |
| SED Replacing all but one regex match on a line or specific matches | vectox | Shell Programming and Scripting | 5 | 05-02-2011 05:01 PM |
| sed replacing in vi, / characters in the middle | Gery | UNIX for Dummies Questions & Answers | 3 | 03-08-2010 10:34 AM |
| help on sed replacing special characters | prvnrk | Shell Programming and Scripting | 11 | 10-01-2008 11:02 AM |
| replacing specific characters in a string | anushree.a | Shell Programming and Scripting | 6 | 08-20-2008 03:49 AM |
|
|