Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [io-redirection]

I/O redirection is used in shell scripting. This feature enables to take the output of a command and redirect it as an input for another command. Or command can take the input from a file instead of the keyboard. The whole process helps connect commands in various ways.

0
votes
1answer
30 views

sed command working only when no outfile is written

I'd like to change this file eq.txt 2018-05-03T18:46:05.050Z 11.8314 44.0586 10 4.3 USGS 2018-05-01T05:16:59.270Z 11.0366 43.2334 10 4.1 USGS 2018-04-26T11:13:20.590Z -5.4109 36.5557 10 4 USGS 2018-...
0
votes
1answer
25 views

Split ssldump output into multiple files for every incoming connection

I am capturing SSL Handshake data using ssldump on the terminal, and using the command sudo ssldump -i enp0s8 -a -A -H -n -x > new_trace to output it into a single file. Currently, the output ...
1
vote
0answers
39 views

Shell redirection - follow name, not a descriptor

I have a shell script that is run in the background and the only thing it does is run 1 command, STDOUT of which is being appended to a file. my_blocking_command >> my_file I want to stop the ...
0
votes
1answer
31 views

How can I store output in bash variable and suppress output to stderr and stdout? [duplicate]

If i'm doing oidvalue=$(snmpget -v 2c -c public localhost 1234) This will store the output of that command in oidvalue, however as it is now, it will print some error to the screen. How can I ...
5
votes
1answer
109 views

Process substitution and redirection using tee

Suppose that you redirect, in bash, the standard output of a command cmd to a file named f.out, and the standard error to f.err, using tee to preserve console printing: cmd 1> >(tee f.out) 2>...
0
votes
0answers
43 views

Storing output in variable for redirection [duplicate]

My question is about the application of redirecting output and input. I have a text file that contains 30 or so trackers. I have a torrent file I'd like to add the trackers to. transmission-edit is ...
3
votes
2answers
59 views

Output redirection is not working with top piped to grep

When I run this command in Linux: $ top -b -d 20 | grep "load average" -A 20 > top.log top.log is always empty. But when I run this command: $ top -b -d 20 | grep "load average" -A 20 | tee top....
1
vote
2answers
42 views

Partial Redirection with additional Piping

There's an auto generated file on a remote location that is constantly changing, I can only view the remote file via ssh user@ip cat luckyNumbers it tells me today's lucky numbers and also passes ...
1
vote
0answers
34 views

Log python http server output to file

I want to start a python webserver in the background and log all of its output to file. Instead the the servers output appears in the terminal. Even tho i guess this is pretty basic ... I've got no ...
2
votes
1answer
38 views

redirect awk exec results to another folder [duplicate]

Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end. I plan ...
2
votes
1answer
63 views

concurrent processing in bash using process expansion, and redirection

Apart from possible races that have to be controlled by using proper synchronisation, it's possible in bash to feed a data source concurrently into multiple pipelines and collect all their outputs ...
2
votes
1answer
63 views

Redirect standard error of one command to standard input of another command

I wish to redirect standard error of one command to standard input of another command like g++ filename.cpp 'redirection' less
0
votes
1answer
37 views

“nohup cat” — write the complete content to the log file rather to concatenate file

I used the below command nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz > fastp-filtered-merged4racon/merge_R1.fq.gz > merge_R1.out.log 2>&1 & but unfortunately, the output went ...
0
votes
2answers
19 views

Overwrite file with stdoutput from cron execution

I have this cron in my crontab 00 01 * * * /srv/python/proj/acquisizione/acquisizioneAOK.sh >> /home/crontab_logs/acquisizioneAOK.out 2>&1; mailx -s "Cron output: acquisizioneAOK" ...
0
votes
1answer
39 views

Permanently redirect stderr to stdout

I have a bash script with many commands, some of which might generate error messages. often, the error messages and output messages are mixed in an apparently incorrect order (for example, I see the ...
0
votes
0answers
16 views

send hex as characters to output to remote end

I'm doing a project for a microcontroller that involves sending and receiving special (non-printable character) data through its serial port. I found myself a simulator (ucsim) so I can test things ...
0
votes
0answers
21 views

save input and output data has passed in adb

i want save all input and output commands has executed in adbd I tried to pull adbd file in sbin folder and extract it to modify and Implement of the idea to write a few lines for create file and do ...
0
votes
2answers
23 views

Showkey with timestamp

How can I record keyboard actions with the timestamp, either to console, or preferably to a file? I have showkey output like: keycode 28 release keycode 30 press keycode 30 release keycode 48 ...
3
votes
1answer
190 views

How to use variables inside back-quotes

I have a bash script that accepts a parameter "$input" and (among other things) directs it into a program and collects the output. Currently my line is: OUTPUT=`./main.exe < $input` But I get ...
0
votes
1answer
53 views

Remote overwrite crontab file with sudo

I'm trying to build a script that automatically takes a file on the remote server and replace with crontab file, but I get permission denied. My idea is to create a shell function for it: ...
0
votes
0answers
55 views

Redirecting input bash

I have a program, that runs on only one Raspberry Pi, but could be run from multiple other computers (through SSH). When I run my program on the Pi, it runs as expected. To be able to run from crontab ...
5
votes
1answer
810 views

What's going on with this dash '-' thing?

I was trying to export the Python environment requirements and this is what I intended to do: conda list -e > requirements.txt However I mistakenly typed this instead: conda list -e -> ...
0
votes
2answers
69 views

How could I know inside a script if stdout has been redirected for it?

I have a script in ksh; depending whether there is a redirection from the command line, I redirect the output via a exec 1>file. How can I test from inside the script itself if the command calling ...
0
votes
2answers
132 views

Nohup: Redirect stderr to file and dismiss stdout

Per default, nohup writes stdout to nohup.out and dismisses stderr. I would like to have it the other way around: write stderr to a file and dismiss stdout.
0
votes
1answer
46 views

redirect created files in a directory from command line

I was wondering if there is any way to redirect created files from a .sh script to a specific directory without modifying the script itself but straight from command line. Let's say: I've a script ...
2
votes
1answer
88 views

Redirect script output both to console and to log

Take a look on the following # more /tmp/myscript #!/bin/bash echo I AM echo BIG GUY echo AND ALSO SMART # bash /tmp/myscript | tee -a >/tmp/log why we not get the output from echo in the ...
3
votes
4answers
146 views

Why does `… | sed 's/^/stdout: /'` print on empty stdin when `… > >(sed 's/^/stdout: /')` doesn't?

I'm trying to understand what causes the difference in these 2 constructs that I thought were functionally equivalent: $ ( echo foo >&2 ) 2> >(sed 's/^/stderr: /') | sed 's/^/stdout: /' ...
0
votes
1answer
46 views

Spaces after io redirection operator? [duplicate]

I've noticed that when writing a shell script, there's a lot of inconsistency in whether people put a space after the I/O redirection operators. For example: foo >bar.txt Will work, but so will ...
-1
votes
3answers
47 views

Oneliner for outputting to file only if string is matched (bash)?

I am making a script where I curl a URL and output to a file like this: curl http://example.com/$1 > $1 Is there any way to make it dismiss anything that doesn't include, say <head>? I ...
21
votes
3answers
2k views

How does this script ensure that only one instance of itself is running?

On 19 Aug 2013, Randal L. Schwartz posted this shell script, which was intended to ensure, on Linux, "that only one instance of [the] script is running, without race conditions or having to clean up ...
1
vote
2answers
124 views

Run parallel command and redirect the output to files with specific name

I can't undestand well how the parallel command works. I need to run this simple command: (100 times) curl https://jsonplaceholder.typicode.com/todos/1 curl https://jsonplaceholder.typicode.com/...
5
votes
3answers
240 views

Portable way to invoke tar with a list of files from stdin

I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content. I had done this as follows: cd /path/to/files/ && find . -type f | cut -...
2
votes
1answer
20 views

Ambigious redirect error on different volumes with mysql

i want to import a database with mysql (running with MAMP): #! /bin/bash # variables currdir=$PWD dbname=TEST dbuser=root dbpass=root dbpath="/applications/MAMP/Library/bin" exname=database if [ "$1"...
1
vote
3answers
34 views

How can I remove a newline from redirected output

Can I remove a newline if I redirect output like this? echo "a" >> file I have something similar in my script which contains a for loop that redirects every character (except numbers) to a ...
0
votes
3answers
89 views

How can you write to a file from the command line without using shell output redirection? [duplicate]

I'm trying to: sudo echo "$USER: my message" > /dev/kmsg to write a message to the dmesg log. This causes a 'permission denied' error, because it is redirecting the output of 'sudo' (while no ...
4
votes
1answer
68 views

What's the purpose of 1> in exec 1> >(logger -s -t tagname) 2>&1?

I just stumbled over exec 1> >(logger -s -t $(basename $0)) 2>&1 which is used to redirect the output of the current script to the system logger (in case you've never seen this, but are ...
0
votes
2answers
90 views

Redirect output to standard out instead of file

I am writing a java wrapper for convert (which is part of image magick). What I want to do is call a command like convert -thumbnail 1024 test.JPG >(cat) to make it print the thumbnails byte stream ...
4
votes
2answers
73 views

Strange behaviour redirecting man pages

I wanted to redirect mc's man page to a text file using man mc > mc, but I accidentally executed man mc > mc grep. What resulted was a text file named mc containing two concatenated mc man pages....
0
votes
1answer
77 views

Bash output redirection to new file each time command is run

I have a Bash one-liner that redirects the output of a command to a new, fresh file each time the command is run. Logging the output of each time the command is run is important (I'm using ls here as ...
0
votes
1answer
16 views

How do I avoid this unexpected behaviour when redirecting output from echo?

I wanted to add to my hosts file easily using a one line command, but I get an unexpected result. $ sudo sh -c 'echo -e "10.0.10.0\tserver.bananas.com\tserver" >> /etc/hosts' $ cat /etc/hosts -...
0
votes
1answer
154 views

-c and -b options not working in mailx in ubuntu

I was trying to send a mail from the shell script using the command mailx -s "TEST MAIL" -c "user_name ..." user<message.txt but it generates an error as unrecognized option -c ,the same happens ...
9
votes
1answer
594 views

Redirecting stdout from two programs

I'm running a memory check tool (prog1) on a C++ code (prog2), both of which give me a huge and detailed output. In order to chase down some bugs I need to save this output to a file. I tried ...
0
votes
0answers
178 views

Cannot pass argument through /proc/<pid>/fd/0

I have written a basic C++ program as such: #include <sstream> #include <unistd.h> #include <cstdio> #include <iostream> int main(void) { int foo; std::cin >> foo; ...
-2
votes
1answer
230 views

Piping output of command to sed

How would i pipe results of a command to sed without using '>>' so it appends that output to file? What i want is something like this command | sed -i "${command output}" file
1
vote
1answer
118 views

Is it possible to get the output of only sudo command?

I want to write the output of only sudo command to some file i.e. the line which I get on terminal after writing sudo i.e. [sudo] password for user: If I use sudo ls > file or sudo ls 2> file ...
2
votes
2answers
41 views

Does output redirection to a block device overwrite bytes or whole blocks?

A comment on another question made me wonder: Assuming I redirect the output from a command to a block device, and the length of that output is less than the block size of the block device: % ...
0
votes
2answers
54 views

How do I diff the output of these two commands? [duplicate]

I have an alias which I use to strip out comments that are piped to it: alias decomment='egrep -v "(^#.*|^$)"' I'm currently having some difficulty with a squid proxy setup, so I want to compare ...
1
vote
1answer
25 views

A command wants file paths. How can I give it stdin for the “infile” and stdout for the “outfile”?

Consider a command like foo -in /path/to/infile -out /path/to/outfile, that you'd like to pass strings to rather than using temp files. It may be called a lot causing much disk access, or is related ...
0
votes
2answers
92 views

What is the end of here string?

It seemed to me that the end of a here string is newline. I realize I am wrong: $ cat <<< hello world cat: world: No such file or directory What can signify the end of a here string?
1
vote
1answer
21 views

What is happening in these MULTIOS redirections?

When I run 1>&2 echo hi |& grep hi, I get a non-colored hi followed by a red hi on a new line. This is the same output as 1>&2 echo hi | grep hi. Why aren’t both of the “hi”s red in ...