On 12/22/2011 10:14 AM, Peng Yu wrote:
> Hi,
> 
> I want to change how the line number is displayed
> 
> ~$ echo a | cat -n
>      1        a
> 
> For example, I want it to be shown as
> 
> 1:a
> 
> Although this can be easily done in anything other scripting language,
> I'm wondering if there is an even easier way to get it done with cat.

Nope, making cat do alternate output styles as an extension would be
adding bloat.  At this point, it's far more portable to use existing
standardized approaches.  My favorite is two invocations of sed (one to
insert line numberings between every line of input, the second to
convert every pair of lines into your desired output format).  For example:

$ seq 2 2 10 | sed = | sed 'N; s/\n/:/'
1:2
2:4
3:6
4:8
5:10

-- 
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to