44ca02c582
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@169 a672b425-5310-4d7a-af5c-997e18724b81
76 lines
1.4 KiB
HTML
76 lines
1.4 KiB
HTML
---
|
|
layout: page
|
|
author: Domenico Votta
|
|
category-page: advanced
|
|
category-title: Advanced commands
|
|
tags: number lines count
|
|
title: nl
|
|
---
|
|
<p>
|
|
The <code>nl</code> is a command that permits to number the lines.
|
|
Through some flags you can decide how to filter this command.<br>
|
|
|
|
We have a file named <code>example.txt</code> that contains 5 elements, to test this command:
|
|
|
|
{% highlight bash linenos %}
|
|
Car
|
|
Computer
|
|
Robot
|
|
Smartphone
|
|
Videogame
|
|
{% endhighlight %}
|
|
|
|
The syntax command is:
|
|
<pre> nl [flags][file] </pre>
|
|
|
|
<pre>
|
|
nl example.txt
|
|
1 Car
|
|
2 Computer
|
|
3 Robot
|
|
4 Smartphone
|
|
5 Videogame
|
|
</pre>
|
|
|
|
How you can see the command has numbered the lines.
|
|
|
|
<h2>Flags</h2>
|
|
|
|
<ul>
|
|
<li> <b>-b (regex)</b>: Specify the lines to be numered
|
|
<pre>
|
|
nl -b p^[cv] example.txt
|
|
1 Car
|
|
2 Computer
|
|
3 Videogame
|
|
Robot
|
|
Smartphone
|
|
</pre>
|
|
<code>p^[cv]</code> says to nl to number only the lines that start with c and v.
|
|
</li>
|
|
|
|
<li> -b<b>n</b>: The flag n goes with b, doesn't number any lines
|
|
<pre>
|
|
nl -bn example.txt
|
|
Car
|
|
Computer
|
|
Videogame
|
|
Robot
|
|
Smartphone
|
|
</pre>
|
|
</li>
|
|
|
|
<li> <b>-s</b>: Usually nl separes the number of the line from the text with a tab, with -s
|
|
flag you can choose another separator, in this example we will use "=".
|
|
<pre>
|
|
nl -s= example.txt
|
|
1=Car
|
|
2=Computer
|
|
3=Videogame
|
|
4=Robot
|
|
5=Smartphone
|
|
</pre>
|
|
</li>
|
|
|
|
</ul>
|
|
</p>
|