You are not logged in.

#1 2017-10-02 13:05:58

huhp
Member
Registered: 2017-01-15
Posts: 4

nl stdout

Anyone else realized that nl's output isn't redirected?
For example

nl > file.txt

and

nl | cat -

fail to produce any output, while

cat file1.txt | nl > file2.txt

does work, so maybe it's because I pressed ^C (even though it works fine with cat)?
However, even weirder is

nl | head -2

which doesn't quit automatically after 2 lines like

cat - | head -2

would.

Any idea how to works around this?

Offline

#2 2017-10-02 13:26:37

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: nl stdout

nl counts the number of lines in a text file, if one is provided on the command line, otherwise it reads from standard input.

You should not press ^C in such a case, but ^D, to send an End of Transmission (EOT). Before you do that, nl will not count any lines.

You may want to read up on how shell redirection and stdin/stdout/stderr work, e.g. https://en.wikipedia.org/wiki/Redirection_(computing)


pkgshackscfgblag

Offline

#3 2017-10-02 13:27:38

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,783
Website

Re: nl stdout

You need to send an EOF (Ctrl+d) to terminate the input, not an interrupt signal (Ctrl+c).

https://www.digitalocean.com/community/ … edirection

Alternatively use a HEREDOC.

http://tldp.org/LDP/abs/html/here-docs.html

EDIT: snaked by ayecat

Last edited by WorMzy (2017-10-02 13:28:07)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2017-10-02 13:33:18

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,089
Website

Re: nl stdout

if you use the first or second command, but end input with ^D (EOT) rather than ^C (fire SIGINT), you will find it properly writes to the file.

I was ninja'd.

All the best,

-HG

Last edited by HalosGhost (2017-10-02 13:33:57)

Offline

Board footer

Powered by FluxBB