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:
^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.
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:
If I'm interpreting this correctly, it seems that most of the solutions presented so far are assuming that volume_name is a literal string that you want to duplicate or didn't understand that the circumflexes were literal field delimiters. I think the following sed command will do what you want even if the strings to be copied or replaced contain any of the characters on the normal shifted and unshifted keys on a US keyboard except for the ^ and : characters. Rather than using the normal slash character as the search pattern delimiter and substitute and replacement string delimiters, it uses the alert character as the delimiter (the character you get by pressing the control key and the g key at the same time). As an example, if you give this script:
sed '\^G[.^.]\([^:]*\):[^^]*[.^.]^Gs^G^G^\\\\\1\\\1^^G' in > out
(where the ^G sequences in the script are alert characters)
an input file named in containing: