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.
This is my first post, I'm taking my first Linux class and I'm stuck mid way through an assignment using sed. I need to "Capitalize the first t in line 5 and 11. (there are many t's in each line). Below is line 5
That will replace the t with T only in the 5th and 11th lines - and only the first instance of the "t"
And just so you know why it works - sed only works on the first instance of what you want to sub(or whatever) on the line you specify (unless you tell it otherwise)- so 5s says only work on the 5th line - then I tell it when you find the first "t" replace it with T - and so on with the 11th line - the -e separates the different sed commands to run - if you wanted to replace all the ts with Ts on lines 5 and 11 you could just add "g" to make it global at the end, like so:
cat <filename> | sed -e '5s/t/T/g' -e '11s/t/T/g'
I am sure that you could do it other ways as well - this is just the easiest IMHO
Huh? I suspect this is a joke? I don't see the command sed nor 5, nor t.
I tried the code but got the message: -bash: syntax error near unexpected token `|'
Thanks for the explanation, I guess I read the syntax wrong that default it only replaces the first instance of it. So with out the g (global) it only replaces the first instance;
You do not want to use the /g in this case - forget it - I was just trying to explain it to you
the "|" is a pipe - you have to pipe the file with cat to sed (well you dont have to but I like to) - just replace the <filename> with the text in the file - I even made a file with your exact line and put it at line 5 and 11 - works perfect - only caps the first t in each line
You are on a linux box right?
O and I see your problem - sed only by default outputs to stdout - it does not save what it did in the file - you have to pipe it too a new file like so