Using the highlighted code at the bottom, I'm trying to achieve the output below:
/dir/subdir/file1.ext
/dir/subdir/file3.ext
However, everything I've tried does not give me the intended results and I always end up with nothing being removed or replaced. Is this even possible using this method or will I have to resort to something like sed?
#!/sbin/sh
testvar="/dir/subdir/file1.ext
/dir/subdir/file2.ext
/dir/subdir/file3.ext"
testvar=${testvar/\/dir\/subdir\/file2.ext\n}
echo $testvar
Thanks, everyone, for the responses. I've tried them all and did not have success with any of the suggestions. The only code that worked for me was the line below.
testvar=${testvar/?dir?subdir?file2.ext?}
Escaping the forward slashes '/' didn't work for me at all. And, while using the wild card '?' does the job, it's very slow in executing. I'll go with it if there's no other way, but if there's any further ideas left, I'd appreciate seeing them. Thanks, again.
\n? And how do you want them? In one variable? How separated? Note that the shell does not expand\nin your example, sotestvarcontains a literal\n, not a newline.