ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
/opt/local/some/dir/
blablablabiugfyugf
"/opt/local/some/dir/file.txt"
"/opt/local/someother/dir/file.bin"
/opt/local/some/dir/file.txt
plaplaplllalalalal
/opt/local/someother/dir/file.bin
MYBEST_DIR="/opt/local/some/dir/"
blablabla
sometimes my favorite path is in the middle of the line /opt/local/somedifrent/dir/file.txt
mmmmrtatatatata
/opt/local/someotherX/dir sometimes is at beginning or...
"opt/local/someother/dir" in this funny sign " <- which i dont know how to call it ;)
What I need to do, is to insert between /opt/ and local/ string NEW/Path/
I was tring with "sed" but it didnt work to me :/
Can anyone help me with this please ?
PMP its almost this what I need but when I replace path with ur code it also erase beginning of the line.
Eg. MYBEST_DIR= will be erased. Same as every sign "
Note that you can use any character in sed's substitution pattern, not just the traditional s///, allowing you to work on file paths. In this case I used s||| (and PMP above used s###).
Note that you can use any character in sed's substitution pattern, not just the traditional s///, allowing you to work on file paths. In this case I used s||| (and PMP above used s###).
btw. I have one more... lets say "half-problem":
What im going to do now, is to use this command on all files on /opt.
So I have written a simple loop:
Code:
#!/bin/bash
files="/opt/*"
for i in $files
do
echo "parsing file $i"
sed 's|/opt/local|/opt/NEW_PATH/local|' $i > $i.out
mv $i.out $i
done
This works fine but I need to re-run script in each dir on /opt file system.
Is there any trick I can use to execute this loop on every sub-dir on /opt file system ?
Of course I can always set: files="/opt/*/*/*" but I must know exactelly count of sub-dirs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.