io redirection is the process of changing where the output and input of a program originate

learn more… | top users | synonyms (1)

2
votes
1answer
51 views

Continously writing terminal output to text file

I am running a small cli python app in terminal. It loops infinitely and outputs text to the terminal. I want to output the text to a file, and I can do that with the following command python [my cli ...
2
votes
1answer
78 views

What are the Linux shells that allow network traffic management (sending/receiving data to/from `/dev/tcp/host/port`) via redirectors?

Following this Bash tutorial, I have succeded in obtaining the code of a web page issuing simple commands by using this method: $ exec 3<>/dev/tcp/www.google.com/80 $ echo -e "GET / ...
15
votes
5answers
1k views

How can the standard input of one program be passed as an arg to another?

Let's say a program exists, which takes two arguments; input file and output file. What if I don't wish to save this output file to disk, but rather pass it straight to stdin of another program. Is ...
1
vote
2answers
84 views

How to while read line with a pipe

I am currently trying read a csv file with BASH. The 10th [$f10] value of the csv file must be greater then 0 for a given machine class and machine ID [m_class] and [m_id] (these are user defined) . ...
2
votes
1answer
104 views

I/O redirection shortcut doesn't work when at the end of a command line

I've been getting myself comfortable with I/O redirection. I've become aware of the &> shortcut for 2>&1. I believe it also works as >&. There may be a nuance to that of which I'm ...
0
votes
4answers
53 views

Excluding specifics lines from being redirected [closed]

Let's say I am executing a script like this : /a/b/c/script.sh >> abc.log This will mean that all the contents/execution of script will be re-directed to abc.log. If I want a particular line ...
0
votes
1answer
29 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
0
votes
0answers
17 views

writefile() to file descriptor produces output with alignment issue

The command that produces weird output: $ vim -ec 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1 line1 line2 $ Same command ...
0
votes
1answer
27 views

More succinct alternative to “lsof -p $(pidof postgres| sed -r 's/ /,/g')”

pidof returns a space separated list of pids. lsof -p requires a comma serparated one. This can be solved with sed via: lsof -p `pidof postgres| sed -r 's/ /,/g'` However, the extra pipe seems a ...
0
votes
0answers
54 views

extract text to csv file from output of reading multiple files into specific rows

I am trying to write a bash script to generate a csv file from text within multiple pdf documents. I have a script for converting pdf to text, but not for generating the csv file. Each text document ...
0
votes
1answer
19 views

Redirect all GnuPG output to /dev/null

I'm doing key generation in a sort of batch mode with GnuPG (don't ask why): echo -e 'addkey\n4\n2048\n120d\nsave' | gpg --command-fd 0 \ --edit-key $master_key_id >/dev/null 2>&1 I ...
4
votes
1answer
86 views

using pipe to run command in background

I was reading this question on rpi and noticed an interesting line that got me thinking: mkfifo tcp.stream nc -l -p 1234 > tcp.stream | omxplayer --live tcp.stream Notice the io redirection. ...
5
votes
2answers
115 views

Silent GnuPG password request with bash commands

I'm trying to hide the "output" of a gnupg command, but it seems that it is always printed. the command is: echo "thisprogramwørks" | gpg -q --status-fd 1 --no-use-agent --sign --local-user D30BDF86 ...
6
votes
1answer
40 views

zsh I/O redirection: redirecting and then piping; what is going on?

Can somebody explain what is going on in this command: echo foo >&2 | grep foo Zsh (5.0.2) prints foo twice. One seemingly to stdout and one to stderr, since running these commands: { echo ...
1
vote
0answers
43 views

Captive portal detection, popup implementation?

Based on hostapd, I m building a captive portal. - My Linux Machine provides a Wifi access. - iPad's and Android clients-tablets connect this Wifi. Generally, any client OS check if a url is ...
1
vote
2answers
67 views

How do I get the output of a program already running?

I have a python program that outputs to stdout and a log file. However, the person I am making this for wants to know if I can set it up so that he can see the output of the file, while it is ...
1
vote
1answer
50 views

zsh: Disable “file exists:” warning with redirection

How can I override the file exists: warning from zsh? > echo > newfile.txt > echo > newfile.txt zsh: file exists: newfile.txt In these cases I prefer my shell to not complain and ...
1
vote
1answer
40 views

How to put “rm -i” in an iteration?

echo "$MOUNTPOINTLIST" | while read onelinefortouch; do touch "${onelinefortouch}testfileforwrite"; done echo "$MOUNTPOINTLIST" | while read onelineforrm; do rm -i "${onelineforrm}testfileforwrite"; ...
1
vote
1answer
25 views

How to redirect tarsnapper output to /dev/null?

I use tarsnapper's make command for managing tarsnap backups like this: tarsnapper -c /usr/local/etc/tarsnapper.conf make Which works like it should and I get an output like this Creating backup ...
2
votes
2answers
40 views

One-liner to sort and uniq two outputs

I'm currently doing this to sort and uniq the output of two different commands: tshark -r sample.pcap -T fields -e eth.src -e ip.src > hello tshark -r sample.pcap -T fields -e eth.dst -e ip.dst ...
0
votes
1answer
16 views

How to redirect the time a task takes to complete into a log file, given that such task is already redirecting?

I have a shell script running a python task, whose stdout is being redirected to a log file: python script.py >> log.txt I wish to also log the time this task takes to complete, into the same ...
5
votes
5answers
278 views

How to use output redirection dynamically?

I'm trying to add a debug option to a script of mine. Normally I want to hide any output, like warnings etc, so I put >/dev/null 2>&1 behind a lot of commands. Now, when I want to debug my ...
2
votes
1answer
50 views

Piping a file that's being written and discarding the contents?

A software writes its logs on a file ("tonsOf.log"). Those logs are mostly useless and I process them later on with some pattern matching (line by line). So, for say 1 GB of logs, I end up with 40KB ...
3
votes
3answers
35 views

Create 2 similar-name files with content from 2-line output of a command

I perform cmd and it outputs 2 lines of text: $ cmd foo bar I need to write these to: `/long/path/x.{load,conf} Writing to this destination requires superuser privilege, which rules out manually ...
0
votes
2answers
58 views

sponge from moreutils - what's the difference to shell redirect? useful examples?

> brew install moreutils ==> Downloading https://homebrew.bintray.com/bottles/moreutils-0.55.yosemite.bottle.tar.gz ...
0
votes
3answers
49 views

What is `>&` in simple terms? [duplicate]

What does $ command 1>&2 do? As I understand it this runs the command but with the STDOUT redirected to the STDERR. But I'm not sure exactly how >& works. I have seen it as $ command ...
0
votes
1answer
52 views

Why doesn't this simple piping with awk work? [duplicate]

I'm trying to follow this answer but I can't make it work. I simplified it down as much as I could to try work out what's going on (just running this at the terminal for now): rsync --progress -iav ...
0
votes
3answers
74 views

Throw away standard output and error

I have redircted my ouput using /dev/null in bash script but it is still throwing an error. Code is following ps -p $proc | fgrep $proc> /dev/null if [ $? -ne '0' ] ; then ...... fi below is ...
4
votes
4answers
431 views

grep command not working in conditional statement

I've a bash script that's supposed to go over all the filenames and print them only those that contain a certain letter (let's say it's 'o'). What I've done: command=`ls -l` for file in $command do ...
1
vote
0answers
35 views

Inherit IO redirections from a script to another

When I redirect the output of a script within a script, I expect the redirection to be applied to the called script as well as the program called within it. A: ./B 2>> error.log B: ...
0
votes
1answer
43 views

need to get the command information over ssh and the input from file

I am writing a script to get the command information of the remote machine usinf while and for loop. PFB the script. But the script ends by giving the single command information only. I have multiple ...
0
votes
0answers
52 views

How to rewrite the comand using I/O redirections?

Is there any way to rewrite the following command using only I/O redirections and not pipes ? ls -l | grep User | wc -l | tail -l
0
votes
1answer
30 views

A generic cron wrapper that records all output

I am hoping to write a cron wrapper that records all output in a folder $CRON_LOG_DIR. It would be used as, e.g., follows: * * * * * $CRON_WRAPPER "<job name>" "command" which would record ...
4
votes
1answer
107 views

Problem with paste and standard output in linux

I have two files that I am trying to merge, one file is: linux$ cat temp2 linear_0_A_B linear_0_B_A 103027.244444 102714.177778 103464.311111 102876.266667 103687.422222 103072.711111 103533.244444 ...
0
votes
2answers
56 views

Write permissions inside of shell script

I am using a Debian 7 Server. I created a shell script to be executed by crontab to save a mysqldump every day. mysqldump *database* -u *mysql-user* -p*mysql-password* > ...
1
vote
1answer
53 views

How to create dynamic process substitution based on the input (multiple FIFOs)?

I'm trying to create multiple process substitutions based on the output from the other command, however I'm not sure how I can achieve that. As sample scenario, I've given list of files: touch a.txt ...
4
votes
3answers
177 views

Redirect the tail output to a file then stop when match found

there is this log file that data coming in is continuous. what i wanted to happen is to tail -f this log file then redirect it to a file with the ff conditions example of the log files content ...
4
votes
1answer
131 views

Redirection to file does not work properly

I have here a bash script: #!/bin/bash TARGET_FILE=ping_result.txt # declare the target ip addresses declare -a ips=("XXX.XXX.XXX.XXX" "YYY.YYY.YYY.YYY") function print_and_log() { echo "$1" ...
1
vote
1answer
70 views

How do I capture output into a variable and still have it goto the screen too?

I can do OUTPUT=$(grunt test) and that puts the output into OUTPUT but it's no longer on the screen. I need to see the output as it comes as well, so I can't just wait and then echo $OUTPUT. How can ...
3
votes
2answers
158 views

Inconsistency of stderr redirection between tcsh and other shells

I'm running into issues with redirection in tcsh. Consider the following commands: vi --version and vi --xxx. And let's assume this is on a machine where vi supports the --version option. The ...
3
votes
2answers
82 views

Linux redirection: << operator [duplicate]

Can anyone explain when and how to use << operator for input redirection? I've googled enough but couldn't find.
1
vote
2answers
109 views

cat < file.txt Who is the responsible of reading the file?

cat < file.txt Who is the responsible of reading the file ? Is the shell reads the open and read the file then write its content to the standard input of the command ?
-1
votes
1answer
27 views

Does those two constructions do the same thing: proces <input.txt vs cat input.txt | process in Linux

Does those two constructions do the same thing: proces <input.txt vs cat input.txt | process in Linux?
1
vote
1answer
56 views

In-place substitution for paste command [duplicate]

When I run the following code echo '1' > file.txt echo '2' | paste file.txt - > file.txt I would expect the content of file.txt be 1 2, because the paste command as it name suggests should ...
2
votes
2answers
84 views

Log both stdin and stdout of program

What I want though is to run a program and log both the stdin and stdout, but I want the stdin to be supplied from a file. I thought script log.txt < input.txt would work, but it does not, because ...
0
votes
1answer
108 views

How to redirect output of a 'xterm -hold -e' command

I know you can use tee to log output from a command in a terminal, e.g.: df -h | tee ~/log.txt However, how can I do this with a more complex command like this: xterm -hold -e program arg1 arg2 ...
5
votes
2answers
566 views

How can I make xargs play nice with stdin?

$ seq 1 3 1 2 3 $ seq 1 3 | xargs echo 1 2 3 $ Mentally replace seq 1 3 with any command that lists entries one-per-line on standard out. How can I get more-or-less what you'd expect, i.e. the ...
1
vote
1answer
64 views

read input from user in while loop having input and output redirection

This is my code: while IFS=',' read a b c; do read input echo $input done 3<&0 < input.csv > output.txt I took care of input redirection by redirecting through pipeline. But ...
1
vote
2answers
65 views

Redirecting stdout and stderr of specific lines

I am reading a file and redirecting the entire output to a file. I would like to redirect stdout and stderr of certain expressions to screen as shown below (just an example): #!/bin/bash OLDIFS=$IFS ...
2
votes
1answer
72 views

cat to stderr while reading to end of file marker

Leaving aside the question of whether usage output should go to stderr or not, if you had to redirect the output of the cat command below to stderr, how would you do it? function usage { cat ...