How do I add tabs to multiple lines of text?
Hi
I have a very simple script to see if NTP is installed: NTP=$(rpm -qa | grep ntp) echo "$NTP" The output is: ntp-4.2.4p8-2.el6.i686 fontpackages-filesystem-1.41-1.1.el6.noarch ntpdate-4.2.4p8-2.el6.i686 How can I get this output to tab all 3 lines so that it looks like this: ntp-4.2.4p8-2.el6.i686 fontpackages-filesystem-1.41-1.1.el6.noarch ntpdate-4.2.4p8-2.el6.i686 I have tried playing around with the /t option but it only tabs the 1st line, the same with using /t in the printf command, would anyone have done something like this before? Thanks |
The text under:
How can I get this output to tab all 3 lines so that it looks like this: should have come out indented, ie with a tab, but the space must have been automatically removed... |
Hi and welcome to LQ.
To correctly display your code preserving any formatting please wrap it in the CODE tags. It'll make it more readable. |
First, the direct solution:
Code:
echo "$NTP" | sed 's/^/\t/' Code:
echo $'\t'"${NTP//$'\n'/$'\n\t'}" Or with printf: Code:
IFS=$'\n' It might be more convenient later on if you stored the output in an array instead, rather than a scalar variable. Code:
|
Thanks Sycamorex
I'll use tags the next time... |
David the H
The solution: echo "$NTP" | sed 's/^/\t/' is exactly what I need, thanks very much for your help and the alternative solutions, Regards |
All times are GMT -5. The time now is 10:19 AM. |