User Tools

Site Tools


sed:numbering:number_each_line_of_a_file_simple_left_alignment

SED - Numbering - Number each line of a file (simple left alignment)

Using a tab instead of space will preserve margins.

sed = filename | sed 'N;s/\n/\t/'

NOTE: = is used to number the line.

The expression \t is used to indicate a tab character (0x09) in the scripts.

Some versions of sed do not recognize the '\t' abbreviation, so when typing these scripts from the command line, you should press the TAB key instead.

'\t' is supported as a regular expression.


Example

Running that command again this file:

testfile
aaa
bbb
ccc

returns:

testfile
1	aaa
2	bbb
3	ccc
sed/numbering/number_each_line_of_a_file_simple_left_alignment.txt · Last modified: 2020/09/27 11:53 by 192.168.1.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki