LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Possible? Issue a command w/output opened by text editor without writing a file? (https://www.linuxquestions.org/questions/linux-general-1/possible-issue-a-command-w-output-opened-by-text-editor-without-writing-a-file-4175693968/)

JASlinux 04-19-2021 10:44 PM

Possible? Issue a command w/output opened by text editor without writing a file?
 
[text editor command] [find . -iname "*apricot*" (instead of filename)]

pipes and redirects?

Turbocapitalist 04-19-2021 10:58 PM

Some editors accept data via stdin. Supposedly nano does too, but here are two examples for vim:

Code:

find . -iname "*apricot*" | vim -

vim - < <(find . -iname "*apricot*")

See "man vim"

The second example above relies on a Bashism, but may also work in a few other shells such as Zsh.

JASlinux 04-20-2021 12:06 AM

Quote:

Originally Posted by Turbocapitalist (Post 6242928)
Some editors accept data via stdin.

"Some" is key.

This distro has geany, leafpad, vi where none open the data.

pan64 04-20-2021 02:06 AM

actually it is not possible. in the background a file will be created anyway and will be opened by the editor. Just you will not able to identify it. By the way editing stdin is pointless. If you just want to see the content (result of that command) don't use an editor, but a pager, like: less, more, cat (or similar).
Code:

find ..... | less

shruggy 04-20-2021 04:10 AM

I don't quite understand what you're up to. The subject of your thread doesn't match its contents.

In simple cases, sed will definitely do:
Code:

find -iname '*apricot*' -exec sed 'editing commands' {} +
Or do you just want to open a bunch of files in an editor all at once? Then almost any editor will do:
Code:

find -iname '*apricot*' -exec geany {} +
Or do you want to edit the output of a pipe before piping it further? For this, the package moreutils provides command vipe. Again, in simple cases sed would be enough:
Code:

command1 | sed 'editing commands' | command2

JASlinux 04-22-2021 09:28 AM

I simply wanted to redirect or pipe the output of the find command to a text editor, unsaved.
Code:

find [parameters] | leafpad
works, but it doesn't work as hoped with other commands. Example:
Code:

cat [textfile] | leafpad
opens the contents of the textfile to an open leafpad document sans file name. But,

Code:

openssl [decryption parameters deciphered to screen (no specific output file)] | leafpad
just opens a blank leafpad window and doesn't decrypt the file because no output file is named.

The -exec switch tends to open a single file even if multiple matching files are in the directory.

Quote:

Originally Posted by shruggy (Post 6242983)
I don't quite understand what you're up to. The subject of your thread doesn't match its contents.

In simple cases, sed will definitely do:
Code:

find -iname '*apricot*' -exec sed 'editing commands' {} +
Or do you just want to open a bunch of files in an editor all at once? Then almost any editor will do:
Code:

find -iname '*apricot*' -exec geany {} +
Or do you want to edit the output of a pipe before piping it further? For this, the package moreutils provides command vipe. Again, in simple cases sed would be enough:
Code:

command1 | sed 'editing commands' | command2


shruggy 04-22-2021 12:32 PM

Quote:

Originally Posted by JASlinux (Post 6243742)
But,

Code:

openssl [decryption parameters deciphered to screen (no specific output file)] | leafpad
just opens a blank leafpad window and doesn't decrypt the file because no output file is named.

It works for me.
Code:

$ cat lvg.txt
This is line 1. I have got Monday Blues.
This is line 2. I don't want to go to office.
This is line 3. I like my boss.
This is line 4. Have a nice day.
This is line 5. Today is Friday. What a relief.
This is line 6. Today is Saturday.
$
openssl base64 -in lvg.txt
VGhpcyBpcyBsaW5lIDEuIEkgaGF2ZSBnb3QgTW9uZGF5IEJsdWVzLgpUaGlzIGlz
IGxpbmUgMi4gSSBkb24ndCB3YW50IHRvIGdvIHRvIG9mZmljZS4KVGhpcyBpcyBs
aW5lIDMuIEkgbGlrZSBteSBib3NzLgpUaGlzIGlzIGxpbmUgNC4gSGF2ZSBhIG5p
Y2UgZGF5LgpUaGlzIGlzIGxpbmUgNS4gVG9kYXkgaXMgRnJpZGF5LiBXaGF0IGEg
cmVsaWVmLgpUaGlzIGlzIGxpbmUgNi4gVG9kYXkgaXMgU2F0dXJkYXkuCg==

And this opens the decoded text in Leafpad just fine:
Code:

openssl base64 -in lvg.txt|openssl base64 -d|leafpad
Edit. I guess I know what your problem is. This has nothing to do with the editor. See Pass Phrase Options in the openssl(1) man page for how to provide password non-interactively. E.g.
Code:

$ cat password
secret
$
openssl aes128 -pbkdf2 -pass file:password -in lvg.txt >lvg.aes
$
openssl aes128 -d -pbkdf2 -pass file:password -in lvg.aes|leafpad


JASlinux 04-23-2021 02:54 AM

Quote:

Originally Posted by shruggy (Post 6243835)
Edit. I guess I know what your problem is. This has nothing to do with the editor. See Pass Phrase Options in the openssl(1) man page for how to provide password non-interactively. E.g.
Code:

$ cat password
secret
$
openssl aes128 -pbkdf2 -pass file:password -in lvg.txt >lvg.aes
$
openssl aes128 -d -pbkdf2 -pass file:password -in lvg.aes|leafpad


Might be. I'm not a tech just a user with advanced needs.

It's easy to make OpenSSL output to screen, just exclude the -out file and stdio is chosen. But sending that to leafpad for me will require more tinkering. Your second line looks good if it'll work.

teckk 04-23-2021 12:34 PM

Quote:

I simply wanted to redirect or pipe the output of the find command to a text editor, unsaved.
Code:

a="This is line one
This is line two
This is line three."

echo "$a" > temp; nano temp
echo "$a" > temp; geany temp

ls -a > temp; leafpad temp

echo "Hello" > tempfile

md5sum tempfile > temp; leafpad temp


JASlinux 04-24-2021 01:09 AM

Looks good but is there ever a file name "temp" sitting in the working directory?

Avoiding file output is the first goal.

Quote:

Originally Posted by teckk (Post 6244214)
Code:

a="This is line one
This is line two
This is line three."

echo "$a" > temp; nano temp
echo "$a" > temp; geany temp

ls -a > temp; leafpad temp

echo "Hello" > tempfile

md5sum tempfile > temp; leafpad temp



Turbocapitalist 04-24-2021 01:46 AM

There has to be a file somewhere. Even when piped 'directly' into an editor, the stream will be saved temporarly by the editor. However, if you make your own temporary file, you can bury it in a temporary directory and then erase both when done:

Code:

#/bin/sh

PATH=/usr/bin:/bin

umask 077

tmpdir=$(mktemp -d /tmp/jas-tmp.XXXXXX)
tmpfile=$(mktemp /tmp/jas-tmp.XXXXXX)

closing() {
    test -d ${tmpdir} || exit 1
    echo "Removing temporary directory (${tmpdir}) and its files."
    rm ${tmpdir}/jas-tmp.*
    rmdir ${tmpdir}
}

abort() {
    echo "Cancelled."
    closure
    exit 2
}

trap "abort" 1 2 15

echo "${a}" > ${tmpfile}
nano ${tmpfile}

trap - 1 2 15

closing

exit 0

The trap is there so that if the process is interrupted, it tries to clean up on the way out. See 'man sh' and 'man 7 signal' about that.

JASlinux 04-27-2021 04:38 AM

Quote:

Originally Posted by Turbocapitalist (Post 6244364)
There has to be a file somewhere. Even when piped 'directly' into an editor, the stream will be saved temporarly by the editor. However, if you make your own temporary file, you can bury it in a temporary directory and then erase both when done:

If a file is erased when the editor is closed without saving, or is obfuscated in some esoteric directory only very technical hands understand, that is acceptable.

I'm still struggling with pipe parameters, because some scenarios it seems to work and others it won't.

Turbocapitalist 05-03-2021 02:54 AM

As an afterthought, another layer to add might be to make a tiny, temporary RAM disk of some kind and keep the temporary file there. The RAM disk can then be removed when the editing has been completed.


All times are GMT -5. The time now is 08:11 PM.