Monday, September 28, 2009

Working with text files in Unix/Linux (part 3/3)

Another complex combination.  To list line numbers on a file the cat command has an option, but the "nl" command has multiple formating options, something that the "cat" command doesnt.

The -n specifies a format and "rz" right justifies with not leading zeros.

cat sourcefile.php | nl -n rz

To see the last 3 lines of any text file use tail:
cat sourcefile.php | tail -n1

To see how many lines a file has, combine them both:
cat sourcefile.php | nl -n rz | tail -n1

0 comentarios: