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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
please help me with the script of going into a directory and edit each file in there. e.g. in /temp there are 8 files and each contain content that contains ABC as consecutive characters somewhere. so, the challenge is to change the ABC to TTT each time it occurs in all the 8 files. the following is what i attampted:
for file in temp_files
file2=`cat $file | tr "ABC" "TTT"`
What does not work exactly? Do you receive some error or just don't get the expected result? Two things I can notice, here. First, the script does not actually edit the files: it simply stores the file content in a shell variable, which is overwritten at each loop. Second, the tr command is not suitable for this kind of substitution, since "ABC" is not interpreted as a string of three characters but as a set of characters, in the sense that every occurrence of A or B or C is substituted by the characters in the second set, not only the literal ABC string.
I suggest to look at the sed editor which gives the possibility to substitute a whole pattern and to edit the files in place, using the -i option. This is a very good tutorial on sed. Anyway, give it a try and ask again if you encounter any problem.
'tr "ABC" "TTT" < input-file > different-output-file && mv different-output-file input-file' translates all occurrences of "A" to "T", all occurrences of "B" to "T", and all occurrences of "C" to "T".
'tr "ABC" "CBA" < input-file > different-output-file && mv different-output-file input-file' translates all occurrences of "A" to "C", all occurrences of "B" to "B", and all occurrences of "C" to "A".
'sed -i "s/ABC/TTT/g" input-file' will change all occurrences of "ABC" to "TTT" in input-file.
A for loop will operate on all your files in turn:
for file in temp_files; do
sed -i 's/ABC/TTT/g' $file
Thanks guys! You guys are great! All the tips worked perfectly fine although I struggled because I confused ' with ` and it gave me errors but I managed to come around it.
And a big thanks to colucix for the tutorial, it will keep me reading:-)
And for all of you guys I dont mean you give me tutorials as solutions please, but they can always make a good company with the solutions I believe :-).