how to find & replace a file path listed in a file
I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep only the actual file name (eg: abcdef.idt). Please note that the idt file need not always be mentioned with absolute path; it can just be the filename alone. There can be only one idt file mentioned in a line (between one < file>..< /file> tag).
This needs to be done for all the files in a directory.
In the below example, see the 3 lines having emptest1.idt, emptest2.idt & emptest3.idt
Sample Input file content (xml file):
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>/test/src/repos/emp.deploy/emptest1.idt</File>
<File>emptest2.idt</File>
<File>
/test/src/repos/emp.deploy/emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
The output has to be:
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
linux awk sed replace xml
add a comment |
I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep only the actual file name (eg: abcdef.idt). Please note that the idt file need not always be mentioned with absolute path; it can just be the filename alone. There can be only one idt file mentioned in a line (between one < file>..< /file> tag).
This needs to be done for all the files in a directory.
In the below example, see the 3 lines having emptest1.idt, emptest2.idt & emptest3.idt
Sample Input file content (xml file):
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>/test/src/repos/emp.deploy/emptest1.idt</File>
<File>emptest2.idt</File>
<File>
/test/src/repos/emp.deploy/emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
The output has to be:
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
linux awk sed replace xml
(1) Will the file paths always be absolute pathnames? (2) Can there be multiple filenames on the same line? (3) Can you ever have</File>…<File>/some/path/emptest2.idt
on the same line? (4) What have you tried? Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Jan 3 at 10:24
Thank You, G-Man!! Per your suggestion, I have provided the information in the question. I am new to linux shell script; so came through sed command by going through google but none of mine worked... sed -n, sed-s.
– viki143
Jan 3 at 10:55
add a comment |
I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep only the actual file name (eg: abcdef.idt). Please note that the idt file need not always be mentioned with absolute path; it can just be the filename alone. There can be only one idt file mentioned in a line (between one < file>..< /file> tag).
This needs to be done for all the files in a directory.
In the below example, see the 3 lines having emptest1.idt, emptest2.idt & emptest3.idt
Sample Input file content (xml file):
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>/test/src/repos/emp.deploy/emptest1.idt</File>
<File>emptest2.idt</File>
<File>
/test/src/repos/emp.deploy/emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
The output has to be:
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
linux awk sed replace xml
I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep only the actual file name (eg: abcdef.idt). Please note that the idt file need not always be mentioned with absolute path; it can just be the filename alone. There can be only one idt file mentioned in a line (between one < file>..< /file> tag).
This needs to be done for all the files in a directory.
In the below example, see the 3 lines having emptest1.idt, emptest2.idt & emptest3.idt
Sample Input file content (xml file):
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>/test/src/repos/emp.deploy/emptest1.idt</File>
<File>emptest2.idt</File>
<File>
/test/src/repos/emp.deploy/emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
The output has to be:
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
linux awk sed replace xml
linux awk sed replace xml
edited Jan 3 at 15:27
Kusalananda
124k16232382
124k16232382
asked Jan 3 at 10:11
viki143viki143
11
11
(1) Will the file paths always be absolute pathnames? (2) Can there be multiple filenames on the same line? (3) Can you ever have</File>…<File>/some/path/emptest2.idt
on the same line? (4) What have you tried? Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Jan 3 at 10:24
Thank You, G-Man!! Per your suggestion, I have provided the information in the question. I am new to linux shell script; so came through sed command by going through google but none of mine worked... sed -n, sed-s.
– viki143
Jan 3 at 10:55
add a comment |
(1) Will the file paths always be absolute pathnames? (2) Can there be multiple filenames on the same line? (3) Can you ever have</File>…<File>/some/path/emptest2.idt
on the same line? (4) What have you tried? Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Jan 3 at 10:24
Thank You, G-Man!! Per your suggestion, I have provided the information in the question. I am new to linux shell script; so came through sed command by going through google but none of mine worked... sed -n, sed-s.
– viki143
Jan 3 at 10:55
(1) Will the file paths always be absolute pathnames? (2) Can there be multiple filenames on the same line? (3) Can you ever have
</File>…<File>/some/path/emptest2.idt
on the same line? (4) What have you tried? Please do not respond in comments; edit your question to make it clearer and more complete.– G-Man
Jan 3 at 10:24
(1) Will the file paths always be absolute pathnames? (2) Can there be multiple filenames on the same line? (3) Can you ever have
</File>…<File>/some/path/emptest2.idt
on the same line? (4) What have you tried? Please do not respond in comments; edit your question to make it clearer and more complete.– G-Man
Jan 3 at 10:24
Thank You, G-Man!! Per your suggestion, I have provided the information in the question. I am new to linux shell script; so came through sed command by going through google but none of mine worked... sed -n, sed-s.
– viki143
Jan 3 at 10:55
Thank You, G-Man!! Per your suggestion, I have provided the information in the question. I am new to linux shell script; so came through sed command by going through google but none of mine worked... sed -n, sed-s.
– viki143
Jan 3 at 10:55
add a comment |
3 Answers
3
active
oldest
votes
You could use:
sed -i -E -e 's/(/.*/)(.*.idt)/2/' file_list
This performs an in-place (-i
) replacement of all /..../filename.idt
filepaths with filename.idt
("all" as in: the first occurrence on each line of a certain file). If there is no absolute path preceding the filename, the regex does not match, and nothing happens. The file_list
can be replaced with an *.xml
or the like at your command prompt. You may want to try running the command without the -i
option first, to see the output before writing it to disk.
add a comment |
Assuming the XML is well formed, the following will remove the string /test/src/repos/emp.deploy/
from the values of each File
node that contains that string and the string .idt
using XMLStarlet (or rather, it leaves the bit of the value that occurs after the path):
xmlstarlet ed -u '//File[contains(., "/test/src/repos/emp.deploy/") and contains(., ".idt")]'
-x 'substring-after(., "/test/src/repos/emp.deploy/")' file.xml
Adding a root
node to your example document and running the above command generates
<?xml version="1.0"?>
<root>
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
</root>
It would be even neater if the following worked:
xmlstrlet ed -u '//File[contains(., ".idt")]'
-x 'replace(.,".*/","")' file.xml
... but XMLStarlet (on my system) doesn't seem to want to know about the replace()
function.
add a comment |
I Have used below method
command: sed '/idt/s//test.*emp.deploy///g' file
output
sed '/idt/s//test.*emp.deploy///g' file1
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
1
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"
– Jeff Schaller
Jan 3 at 18:11
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492201%2fhow-to-find-replace-a-file-path-listed-in-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use:
sed -i -E -e 's/(/.*/)(.*.idt)/2/' file_list
This performs an in-place (-i
) replacement of all /..../filename.idt
filepaths with filename.idt
("all" as in: the first occurrence on each line of a certain file). If there is no absolute path preceding the filename, the regex does not match, and nothing happens. The file_list
can be replaced with an *.xml
or the like at your command prompt. You may want to try running the command without the -i
option first, to see the output before writing it to disk.
add a comment |
You could use:
sed -i -E -e 's/(/.*/)(.*.idt)/2/' file_list
This performs an in-place (-i
) replacement of all /..../filename.idt
filepaths with filename.idt
("all" as in: the first occurrence on each line of a certain file). If there is no absolute path preceding the filename, the regex does not match, and nothing happens. The file_list
can be replaced with an *.xml
or the like at your command prompt. You may want to try running the command without the -i
option first, to see the output before writing it to disk.
add a comment |
You could use:
sed -i -E -e 's/(/.*/)(.*.idt)/2/' file_list
This performs an in-place (-i
) replacement of all /..../filename.idt
filepaths with filename.idt
("all" as in: the first occurrence on each line of a certain file). If there is no absolute path preceding the filename, the regex does not match, and nothing happens. The file_list
can be replaced with an *.xml
or the like at your command prompt. You may want to try running the command without the -i
option first, to see the output before writing it to disk.
You could use:
sed -i -E -e 's/(/.*/)(.*.idt)/2/' file_list
This performs an in-place (-i
) replacement of all /..../filename.idt
filepaths with filename.idt
("all" as in: the first occurrence on each line of a certain file). If there is no absolute path preceding the filename, the regex does not match, and nothing happens. The file_list
can be replaced with an *.xml
or the like at your command prompt. You may want to try running the command without the -i
option first, to see the output before writing it to disk.
edited Jan 3 at 14:51
answered Jan 3 at 14:35
ozzyozzy
4664
4664
add a comment |
add a comment |
Assuming the XML is well formed, the following will remove the string /test/src/repos/emp.deploy/
from the values of each File
node that contains that string and the string .idt
using XMLStarlet (or rather, it leaves the bit of the value that occurs after the path):
xmlstarlet ed -u '//File[contains(., "/test/src/repos/emp.deploy/") and contains(., ".idt")]'
-x 'substring-after(., "/test/src/repos/emp.deploy/")' file.xml
Adding a root
node to your example document and running the above command generates
<?xml version="1.0"?>
<root>
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
</root>
It would be even neater if the following worked:
xmlstrlet ed -u '//File[contains(., ".idt")]'
-x 'replace(.,".*/","")' file.xml
... but XMLStarlet (on my system) doesn't seem to want to know about the replace()
function.
add a comment |
Assuming the XML is well formed, the following will remove the string /test/src/repos/emp.deploy/
from the values of each File
node that contains that string and the string .idt
using XMLStarlet (or rather, it leaves the bit of the value that occurs after the path):
xmlstarlet ed -u '//File[contains(., "/test/src/repos/emp.deploy/") and contains(., ".idt")]'
-x 'substring-after(., "/test/src/repos/emp.deploy/")' file.xml
Adding a root
node to your example document and running the above command generates
<?xml version="1.0"?>
<root>
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
</root>
It would be even neater if the following worked:
xmlstrlet ed -u '//File[contains(., ".idt")]'
-x 'replace(.,".*/","")' file.xml
... but XMLStarlet (on my system) doesn't seem to want to know about the replace()
function.
add a comment |
Assuming the XML is well formed, the following will remove the string /test/src/repos/emp.deploy/
from the values of each File
node that contains that string and the string .idt
using XMLStarlet (or rather, it leaves the bit of the value that occurs after the path):
xmlstarlet ed -u '//File[contains(., "/test/src/repos/emp.deploy/") and contains(., ".idt")]'
-x 'substring-after(., "/test/src/repos/emp.deploy/")' file.xml
Adding a root
node to your example document and running the above command generates
<?xml version="1.0"?>
<root>
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
</root>
It would be even neater if the following worked:
xmlstrlet ed -u '//File[contains(., ".idt")]'
-x 'replace(.,".*/","")' file.xml
... but XMLStarlet (on my system) doesn't seem to want to know about the replace()
function.
Assuming the XML is well formed, the following will remove the string /test/src/repos/emp.deploy/
from the values of each File
node that contains that string and the string .idt
using XMLStarlet (or rather, it leaves the bit of the value that occurs after the path):
xmlstarlet ed -u '//File[contains(., "/test/src/repos/emp.deploy/") and contains(., ".idt")]'
-x 'substring-after(., "/test/src/repos/emp.deploy/")' file.xml
Adding a root
node to your example document and running the above command generates
<?xml version="1.0"?>
<root>
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
</root>
It would be even neater if the following worked:
xmlstrlet ed -u '//File[contains(., ".idt")]'
-x 'replace(.,".*/","")' file.xml
... but XMLStarlet (on my system) doesn't seem to want to know about the replace()
function.
edited Jan 3 at 15:34
answered Jan 3 at 15:22
KusalanandaKusalananda
124k16232382
124k16232382
add a comment |
add a comment |
I Have used below method
command: sed '/idt/s//test.*emp.deploy///g' file
output
sed '/idt/s//test.*emp.deploy///g' file1
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
1
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"
– Jeff Schaller
Jan 3 at 18:11
add a comment |
I Have used below method
command: sed '/idt/s//test.*emp.deploy///g' file
output
sed '/idt/s//test.*emp.deploy///g' file1
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
1
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"
– Jeff Schaller
Jan 3 at 18:11
add a comment |
I Have used below method
command: sed '/idt/s//test.*emp.deploy///g' file
output
sed '/idt/s//test.*emp.deploy///g' file1
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
I Have used below method
command: sed '/idt/s//test.*emp.deploy///g' file
output
sed '/idt/s//test.*emp.deploy///g' file1
<Application Name="empBnf" ServiceType="SOAP" BitMode="32" Path="/test/bin"/>
<FileList>
<File>emptest1.idt</File>
<File>emptest2.idt</File>
<File>
emptest3.idt
</File>
<File>/test/src/repos/emp.deploy/emptest.wsdl</File>
</FileList>
<Service Qualifier="http://www.mytest.com/test/empbnf" Name="/test/src/repos/empBnf" XManagement="Container">
<Operation>Operation</Operation>
</Service>
answered Jan 3 at 17:50
Praveen Kumar BSPraveen Kumar BS
1,250138
1,250138
1
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"
– Jeff Schaller
Jan 3 at 18:11
add a comment |
1
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"
– Jeff Schaller
Jan 3 at 18:11
1
1
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "
if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"– Jeff Schaller
Jan 3 at 18:11
I'd recommend a more-general replacement, instead of requiring "test.*emp.deploy", as the OP said "
if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path
" -- I wouldn't assume that every path matches "test.*emp.deploy"– Jeff Schaller
Jan 3 at 18:11
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492201%2fhow-to-find-replace-a-file-path-listed-in-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
(1) Will the file paths always be absolute pathnames? (2) Can there be multiple filenames on the same line? (3) Can you ever have
</File>…<File>/some/path/emptest2.idt
on the same line? (4) What have you tried? Please do not respond in comments; edit your question to make it clearer and more complete.– G-Man
Jan 3 at 10:24
Thank You, G-Man!! Per your suggestion, I have provided the information in the question. I am new to linux shell script; so came through sed command by going through google but none of mine worked... sed -n, sed-s.
– viki143
Jan 3 at 10:55