coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: cat -n with different format?


From: Voelker, Bernhard
Subject: RE: cat -n with different format?
Date: Mon, 2 Jan 2012 11:32:22 +0100

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.

Additionally to the solutions using sed or nl provided
by Eric and Erik, this also works:

$ seq 2 2 10 | awk '{print NR ":" $0}'
1:2
2:4
3:6
4:8
5:10
$ seq 2 2 10 | grep -n '^'
1:2
2:4
3:6
4:8
5:10

Interestingly, grep also accepts an empty empression ''
but I can't find information in the manual about what
grep will do in such a case:
http://www.gnu.org/software/grep/manual/grep.html

$ seq 2 2 10 | grep -n ''
1:2
2:4
3:6
4:8
5:10

Have a nice day,
Berny


reply via email to

[Prev in Thread] Current Thread [Next in Thread]