Correct pipe useHow do I correct a directory incorrectly copied into itself?Trouble getting menu to workfind, xargs and mv: renaming files with double-quotes, expansion and bash precedence issueMerge and print matching and non matching values between a smaller file and a huge filelimit inotifywait output to n/secWait for stdout stream to finish and then add its contents to a fileHow to overwrite output file on every input updateadding filepath in the filesRedirection and piping for greppingPipe from a while loop to a command but execute another command if pipe command fails

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

Which is the best way to check return result?

Why can't we play rap on piano?

What does “the session was packed” mean in this context?

Should I tell management that I intend to leave due to bad software development practices?

iPad being using in wall mount battery swollen

Why do bosons tend to occupy the same state?

What killed these X2 caps?

Why no variance term in Bayesian logistic regression?

How seriously should I take size and weight limits of hand luggage?

Can we compute the area of a quadrilateral with one right angle when we only know the lengths of any three sides?

Why are the 737's rear doors unusable in a water landing?

What mechanic is there to disable a threat instead of killing it?

What exploit Are these user agents trying to use?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Is it inappropriate for a student to attend their mentor's dissertation defense?

Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?

Detention in 1997

Why didn't Miles's spider sense work before?

Am I breaking OOP practice with this architecture?

What is a romance in Latin?

Avoiding direct proof while writing proof by induction

Intersection Puzzle

Is it possible to create a QR code using text?



Correct pipe use


How do I correct a directory incorrectly copied into itself?Trouble getting menu to workfind, xargs and mv: renaming files with double-quotes, expansion and bash precedence issueMerge and print matching and non matching values between a smaller file and a huge filelimit inotifywait output to n/secWait for stdout stream to finish and then add its contents to a fileHow to overwrite output file on every input updateadding filepath in the filesRedirection and piping for greppingPipe from a while loop to a command but execute another command if pipe command fails













0















I am currently doing:



cat file1 file2 | sort -k1,1 > temp_file
command [options] -i temp_file > result_file


-i specifies the command input, in this case the file; I want a way to do this without explicitly specifying a temp_file.



cat file1 file2 | sort -k1,1 | command [options] -i > result_file fails, complaining there's no file after the -i.



I also tried xargs but that led to execution on every line of content instead of on the file.










share|improve this question









New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • How can i know if it does or not?

    – codeprimate123
    2 days ago






  • 1





    Does your system provide either /dev/stdin or /proc/self/fd/0? If so you might be able to use them as the filename after the -i, i.e. sort -k1,1 file1 file2 | command [options] -i /dev/stdin (no cat needed). A big limitation of piped input is that the program can not use the lseek or seek calls on it so the program must be written to process the data sequentially or else provide its own buffering.

    – icarus
    2 days ago















0















I am currently doing:



cat file1 file2 | sort -k1,1 > temp_file
command [options] -i temp_file > result_file


-i specifies the command input, in this case the file; I want a way to do this without explicitly specifying a temp_file.



cat file1 file2 | sort -k1,1 | command [options] -i > result_file fails, complaining there's no file after the -i.



I also tried xargs but that led to execution on every line of content instead of on the file.










share|improve this question









New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • How can i know if it does or not?

    – codeprimate123
    2 days ago






  • 1





    Does your system provide either /dev/stdin or /proc/self/fd/0? If so you might be able to use them as the filename after the -i, i.e. sort -k1,1 file1 file2 | command [options] -i /dev/stdin (no cat needed). A big limitation of piped input is that the program can not use the lseek or seek calls on it so the program must be written to process the data sequentially or else provide its own buffering.

    – icarus
    2 days ago













0












0








0








I am currently doing:



cat file1 file2 | sort -k1,1 > temp_file
command [options] -i temp_file > result_file


-i specifies the command input, in this case the file; I want a way to do this without explicitly specifying a temp_file.



cat file1 file2 | sort -k1,1 | command [options] -i > result_file fails, complaining there's no file after the -i.



I also tried xargs but that led to execution on every line of content instead of on the file.










share|improve this question









New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am currently doing:



cat file1 file2 | sort -k1,1 > temp_file
command [options] -i temp_file > result_file


-i specifies the command input, in this case the file; I want a way to do this without explicitly specifying a temp_file.



cat file1 file2 | sort -k1,1 | command [options] -i > result_file fails, complaining there's no file after the -i.



I also tried xargs but that led to execution on every line of content instead of on the file.







bash shell-script






share|improve this question









New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









K7AAY

909928




909928






New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









codeprimate123codeprimate123

31




31




New contributor




codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






codeprimate123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • How can i know if it does or not?

    – codeprimate123
    2 days ago






  • 1





    Does your system provide either /dev/stdin or /proc/self/fd/0? If so you might be able to use them as the filename after the -i, i.e. sort -k1,1 file1 file2 | command [options] -i /dev/stdin (no cat needed). A big limitation of piped input is that the program can not use the lseek or seek calls on it so the program must be written to process the data sequentially or else provide its own buffering.

    – icarus
    2 days ago

















  • How can i know if it does or not?

    – codeprimate123
    2 days ago






  • 1





    Does your system provide either /dev/stdin or /proc/self/fd/0? If so you might be able to use them as the filename after the -i, i.e. sort -k1,1 file1 file2 | command [options] -i /dev/stdin (no cat needed). A big limitation of piped input is that the program can not use the lseek or seek calls on it so the program must be written to process the data sequentially or else provide its own buffering.

    – icarus
    2 days ago
















How can i know if it does or not?

– codeprimate123
2 days ago





How can i know if it does or not?

– codeprimate123
2 days ago




1




1





Does your system provide either /dev/stdin or /proc/self/fd/0? If so you might be able to use them as the filename after the -i, i.e. sort -k1,1 file1 file2 | command [options] -i /dev/stdin (no cat needed). A big limitation of piped input is that the program can not use the lseek or seek calls on it so the program must be written to process the data sequentially or else provide its own buffering.

– icarus
2 days ago





Does your system provide either /dev/stdin or /proc/self/fd/0? If so you might be able to use them as the filename after the -i, i.e. sort -k1,1 file1 file2 | command [options] -i /dev/stdin (no cat needed). A big limitation of piped input is that the program can not use the lseek or seek calls on it so the program must be written to process the data sequentially or else provide its own buffering.

– icarus
2 days ago










1 Answer
1






active

oldest

votes


















4














Some applications understand - there to mean stdin (check its man page), so



sort... | cmd -i - > result.txt


Most systems have a /dev/stdin special file (same as /dev/fd/0), which when open behaves like duplicating stdin, so:



sort... | cmd -i /dev/stdin > result.txt


With some shells (ksh, zsh, bash), you can also write it:



cmd -i <(sort...) > result.txt


While that would work, that file is a pipe so is not seekable. Some cmds may require a seekable file or a regular file and would fail if the file is a pipe. Then, you would have no other option than using a temporary file.



With zsh, you can use the =(...) form of process substitution:



cmd -i =(sort ...) > result.txt


for zsh to create and populate and cleanup the temporary file automatically.



Same with fish, using psub:



cmd -i (sort... | psub -f) > result.txt


With bash, still using a /dev/fd/x file but this time on a regular temporary file, deleted straight after it's opened for a more reliable clean-up:



tmp=$(mktemp) && 
rm -f -- "$file" &&
sort... >&3 3>&- 4<&- &&
cmd -i /dev/fd/4 3>&-
3> "$tmp" 4< "$tmp"





share|improve this answer

























  • The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

    – codeprimate123
    2 days ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






codeprimate123 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509879%2fcorrect-pipe-use%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Some applications understand - there to mean stdin (check its man page), so



sort... | cmd -i - > result.txt


Most systems have a /dev/stdin special file (same as /dev/fd/0), which when open behaves like duplicating stdin, so:



sort... | cmd -i /dev/stdin > result.txt


With some shells (ksh, zsh, bash), you can also write it:



cmd -i <(sort...) > result.txt


While that would work, that file is a pipe so is not seekable. Some cmds may require a seekable file or a regular file and would fail if the file is a pipe. Then, you would have no other option than using a temporary file.



With zsh, you can use the =(...) form of process substitution:



cmd -i =(sort ...) > result.txt


for zsh to create and populate and cleanup the temporary file automatically.



Same with fish, using psub:



cmd -i (sort... | psub -f) > result.txt


With bash, still using a /dev/fd/x file but this time on a regular temporary file, deleted straight after it's opened for a more reliable clean-up:



tmp=$(mktemp) && 
rm -f -- "$file" &&
sort... >&3 3>&- 4<&- &&
cmd -i /dev/fd/4 3>&-
3> "$tmp" 4< "$tmp"





share|improve this answer

























  • The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

    – codeprimate123
    2 days ago















4














Some applications understand - there to mean stdin (check its man page), so



sort... | cmd -i - > result.txt


Most systems have a /dev/stdin special file (same as /dev/fd/0), which when open behaves like duplicating stdin, so:



sort... | cmd -i /dev/stdin > result.txt


With some shells (ksh, zsh, bash), you can also write it:



cmd -i <(sort...) > result.txt


While that would work, that file is a pipe so is not seekable. Some cmds may require a seekable file or a regular file and would fail if the file is a pipe. Then, you would have no other option than using a temporary file.



With zsh, you can use the =(...) form of process substitution:



cmd -i =(sort ...) > result.txt


for zsh to create and populate and cleanup the temporary file automatically.



Same with fish, using psub:



cmd -i (sort... | psub -f) > result.txt


With bash, still using a /dev/fd/x file but this time on a regular temporary file, deleted straight after it's opened for a more reliable clean-up:



tmp=$(mktemp) && 
rm -f -- "$file" &&
sort... >&3 3>&- 4<&- &&
cmd -i /dev/fd/4 3>&-
3> "$tmp" 4< "$tmp"





share|improve this answer

























  • The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

    – codeprimate123
    2 days ago













4












4








4







Some applications understand - there to mean stdin (check its man page), so



sort... | cmd -i - > result.txt


Most systems have a /dev/stdin special file (same as /dev/fd/0), which when open behaves like duplicating stdin, so:



sort... | cmd -i /dev/stdin > result.txt


With some shells (ksh, zsh, bash), you can also write it:



cmd -i <(sort...) > result.txt


While that would work, that file is a pipe so is not seekable. Some cmds may require a seekable file or a regular file and would fail if the file is a pipe. Then, you would have no other option than using a temporary file.



With zsh, you can use the =(...) form of process substitution:



cmd -i =(sort ...) > result.txt


for zsh to create and populate and cleanup the temporary file automatically.



Same with fish, using psub:



cmd -i (sort... | psub -f) > result.txt


With bash, still using a /dev/fd/x file but this time on a regular temporary file, deleted straight after it's opened for a more reliable clean-up:



tmp=$(mktemp) && 
rm -f -- "$file" &&
sort... >&3 3>&- 4<&- &&
cmd -i /dev/fd/4 3>&-
3> "$tmp" 4< "$tmp"





share|improve this answer















Some applications understand - there to mean stdin (check its man page), so



sort... | cmd -i - > result.txt


Most systems have a /dev/stdin special file (same as /dev/fd/0), which when open behaves like duplicating stdin, so:



sort... | cmd -i /dev/stdin > result.txt


With some shells (ksh, zsh, bash), you can also write it:



cmd -i <(sort...) > result.txt


While that would work, that file is a pipe so is not seekable. Some cmds may require a seekable file or a regular file and would fail if the file is a pipe. Then, you would have no other option than using a temporary file.



With zsh, you can use the =(...) form of process substitution:



cmd -i =(sort ...) > result.txt


for zsh to create and populate and cleanup the temporary file automatically.



Same with fish, using psub:



cmd -i (sort... | psub -f) > result.txt


With bash, still using a /dev/fd/x file but this time on a regular temporary file, deleted straight after it's opened for a more reliable clean-up:



tmp=$(mktemp) && 
rm -f -- "$file" &&
sort... >&3 3>&- 4<&- &&
cmd -i /dev/fd/4 3>&-
3> "$tmp" 4< "$tmp"






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









Stéphane ChazelasStéphane Chazelas

312k57592948




312k57592948












  • The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

    – codeprimate123
    2 days ago

















  • The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

    – codeprimate123
    2 days ago
















The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

– codeprimate123
2 days ago





The first solution worked, using the - it processed the as it was a file. I will try and remember the others as well. Great answer, thank you!

– codeprimate123
2 days ago










codeprimate123 is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















codeprimate123 is a new contributor. Be nice, and check out our Code of Conduct.












codeprimate123 is a new contributor. Be nice, and check out our Code of Conduct.











codeprimate123 is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509879%2fcorrect-pipe-use%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.