LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-19-2021, 10:44 PM   #1
JASlinux
Member
 
Registered: Oct 2020
Posts: 95

Rep: Reputation: Disabled
Question 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?
 
Old 04-19-2021, 10:58 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,617
Blog Entries: 3

Rep: Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871
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.
 
Old 04-20-2021, 12:06 AM   #3
JASlinux
Member
 
Registered: Oct 2020
Posts: 95

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Some editors accept data via stdin.
"Some" is key.

This distro has geany, leafpad, vi where none open the data.
 
Old 04-20-2021, 02:06 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,510

Rep: Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552Reputation: 5552
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
 
Old 04-20-2021, 04:10 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,326

Rep: Reputation: Disabled
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
 
Old 04-22-2021, 09:28 AM   #6
JASlinux
Member
 
Registered: Oct 2020
Posts: 95

Original Poster
Rep: Reputation: Disabled
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 View Post
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

Last edited by JASlinux; 04-22-2021 at 09:47 AM. Reason: adding info
 
Old 04-22-2021, 12:32 PM   #7
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,326

Rep: Reputation: Disabled
Quote:
Originally Posted by JASlinux View Post
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

Last edited by shruggy; 04-22-2021 at 01:16 PM.
 
Old 04-23-2021, 02:54 AM   #8
JASlinux
Member
 
Registered: Oct 2020
Posts: 95

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
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.
 
Old 04-23-2021, 12:34 PM   #9
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 3,520

Rep: Reputation: 1095Reputation: 1095Reputation: 1095Reputation: 1095Reputation: 1095Reputation: 1095Reputation: 1095Reputation: 1095
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
 
Old 04-24-2021, 01:09 AM   #10
JASlinux
Member
 
Registered: Oct 2020
Posts: 95

Original Poster
Rep: Reputation: Disabled
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 View Post
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
 
Old 04-24-2021, 01:46 AM   #11
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,617
Blog Entries: 3

Rep: Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871
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.
 
Old 04-27-2021, 04:38 AM   #12
JASlinux
Member
 
Registered: Oct 2020
Posts: 95

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
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.
 
Old 05-03-2021, 02:54 AM   #13
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,617
Blog Entries: 3

Rep: Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871Reputation: 2871
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.
 
  


Reply

Tags
command line, pipes, redirects, text editor


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
video works on vlc if opened in brower but does not works if opened in file manager DRAGSTER_TUNER Linux - Desktop 17 11-05-2018 04:34 AM
Wrote Shell in C - piping output from first command to second command, sending to output file issue KarenWest Programming 2 03-31-2016 05:27 PM
Bash Script - Supressing Command Output and Writing to Text File Nexusfactor Programming 4 07-03-2015 01:22 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration