an other BASH question. trying to put a '- ' at the front of all lines in a txt file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
an other BASH question. trying to put a '- ' at the front of all lines in a txt file
i am trying to take advantage of the excludes.conf file that resides in a directory we backup nightly/hourly (for rsync) to get the --exclude-from=excludes.txt. i am trying to create the excludes.txt in my rsync script.
I found a bit of code, but I was unable to make it work. mainly due to the fact I dont know enough about coding.
Code:
for excludes.txt in /usr/rx30
do
while read -r line
do
echo "- ${line}"
done < ${excludes.txt} >temp
mv temp ${excludes.txt}
done
This provided the error on line 9, the last line of the code, excludes.txt is invalid. sorry i lost the error.
correct, I understand I did it wrong with my above bit of code. Again I am trying to take the existing excludes.conf and create excludes.txt to be used with the rsync command.
The excludes.conf contains the proper list of files/types/directories I would like to 'ignore' in the rsync. The format is slightly different between the two files as well. the .conf does not require the '_' or '+' while the .txt will.
I am looking for a bit of code to take the excludes.conf mv excludes.txt and at the same time add the '- ' to the beginning of each line without the ''.
this is some of what I have read on the --exclude-from=foo
Code:
The"exclude-from" file
The exclude file is a list of directory and file names to be excluded from the rsync destination e.g.
+ /source1/.fileA
- /source1/.*
- /source1/junk/
The format of the exclude file is one pattern per line. The pattern can be a literal string, wildcard, or character range.
In UNIX, hidden files start with a dot (.fileA is a hidden file), and * is a wildcard (.* means all hidden files).
A leading "+" means include the pattern. A leading "-" means exclude the pattern.
A path with a leading-slash must start with the source directory name (not the entire path).
Trailing slash is a directory (not a file). No trailing slash can be a directory or a file.
Lines in an exclude file are read verbatim. One frequent error is leaving some extra whitespace after a file name.
thus allowing for either a path and or a wildcard as well as hidden files.
psyhe, are you saying it will modify the excludes.conf? i dont want that, i still need to have the output in excludes.txt as each of the two files is used for different things. the excludes.conf is for tar and the .txt is for rsync.
I can only state again that this whole script is not necessary. This is my exclude-file, which I use with rsync to backup my Slackware system on my main computer:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.