Shell scripting: How to add characters at the end of the line
How do I add new characters to the end of a line?
For example if I do: Code:
echo testing > test Code:
testing Code:
testingtesting |
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 |
Perfect! Exactly what I needed!!!!!!!!! Thank you! I'll try the echo -n first. I'll ask again if I need help with sed
|
another way is using printf
|
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.
|
Just an FYI. The '-n' option may not be present for some unix users. So printf tends to be used instead to make scripts more portable.
|
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. |
All times are GMT -5. The time now is 03:16 PM. |