Shell scripting: How to add characters at the end of the line
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.
You could try not putting an end-of-line in your first echo. To keep the option open for doing it again, don’t put an end-of-line in any subsequent echo’s.
E.g.,
Code:
echo -n testing > test
echo -n testing >> test
Alternatively, you can use sed (which will work even when you want to add characters to a line in the middle of the file). If you need help with that, just post.
Last edited by osor; 05-17-2007 at 09:51 PM.
Reason: typo
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
Awesome! Good to know about printf. It's always good to be able to do something more than one ways. I will try my script tomorrow on these CSV files at work.
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
In general, are there any significant differences between using printf and echo? What are the advantages and disadvantages besides certain Unix shells not understanding echo -n?
For your specific qn, prob not a lot, but obviously printf gives you nice field formatting/control.
You may need this to construct a properly formed CSV, eg put quote marks around any data field that contains a comma.
Also, if you ever have to change the separator eg use tabs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.