Launch nano editor passing piped command

4k views Asked by At

this is a curiosity. Can i start nano editor from bash, passing a piped command? this is my situation: I've a log file with dates formatted in tai64. For print my file i launch:

$> cat /var/log/qmail/current | tai64nlocal

that print what i want. but i want to view this in nano or another editor in one command. for example:

$> cat /var/log/qmail/current | tai64nlocal > nano

but this doesn't work. Any suggestion? Thanks in advance

4

There are 4 answers

8
konsolebox On BEST ANSWER

Use process substitution:

nano <(cat /var/log/qmail/current | tai64nlocal)

Also, you don't need to use cat

nano <(tai64nlocal < /var/log/qmail/current)
2
umläute On

if you want to nano to open stdin use dash-notation (-):

echo "foo" | nano -

in your case this would translate to

cat /var/log/qmail/current | tai64nlocal | nano -
0
user10647885 On

davymartu's command "nano < ( cat /var/log/maillog | tai64nlocal )" generates a syntax error because of the space between "<" and "(". If the space is removed, as it is in konsolebox's examples, the command will execute.

0
cde On

It didn't work because you are not using pipes. You are using a redirect which works slightly different.

| vs >

By doing

 cat /var/log/qmail/current | tai64nlocal > nano

You are piping cat's stdout to tai64nlocal stdin. Then you redirect it's stdout to a filestream, in this case a file named nano in your pwd.

Based on what you wanted, it partially works because the tai command does both printing and echoing to stdout.

Older versions of nano do not support being piped to though. This was introduced in nano 2.2.

You would do

 Command | nano -

The single dash tells nano to open stdin as a pager, like more or less would.