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

learn more… | top users | synonyms (1)

1
vote
1answer
33 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
100 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
103 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
35 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
131 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
62 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
86 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
24 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
36 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
55 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
16 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
455 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
40 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
57 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
26 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 ...
1
vote
2answers
51 views

pipe in shell with redirection

My understanding is that a pipe in shell like a | b redirects b's stdin to a's stdout. However, I tried ls | less < somefile, the behavior is very strange. less shows the output of ls concatenated ...
3
votes
1answer
20 views

vipe misbehaving on bash process substitution

I have the following simple command: $ echo <(vipe) I expected it to open a vim buffer, which I can edit, then when I'm done, echo the name of the temporary file assigned to hold the vim buffer ...
1
vote
2answers
33 views

CSH and all output (with errors) to file

I need save all output from compilation to file. I have many errors "undefined reference" and I want see all of these errors. I try "makeall >& out", but in file "out" aren't any of error ...
0
votes
1answer
26 views

append file with history line number values

Is there a way to append my_computer.sh with the command on line 330 by only referencing the line number? or with the fewest keystrokes possible? 326 pip install -U pip 327 man pip 328 cat ...
1
vote
3answers
82 views

Store stdout and stderr in file, then recreate the output later

I've redirected output to a file like so: $ ./test.bash 2> >(sed 's/^/stderr: /' >> output) > >(sed 's/^/stdout: /' >> output) $ cat output stdout: Hello World! stderr: ...
0
votes
2answers
41 views

Its possible use special characters in a shell function name?

I have to create the function in shell script, that function name must contain the special characters. like >() { echo $1 $2 } Here my function name is >, If its ...
0
votes
1answer
50 views

Can a command in a shell pipeline determine the tty characteristics of its context?

I have a bash script that columnizes a list of items. By default it will guess at the number of columns to output, based on the terminal width as reported by stty size. But when the script is in a ...
1
vote
1answer
55 views

Bash: using both way redirections in a shell script

I'm writing a shell script to compress and backup certain files. This will compress and move large files with sizes up to 4 GB. I'm having trouble with this line: gzip < $filelocation > ...
1
vote
1answer
63 views

awk with variables in condition and in output redirection file

I would please like some help with this command because I didn't find anything in documentation that can cover everything I want. I have some variables that are global, so I would prefer to keep them ...
1
vote
2answers
65 views

Redirect script output to /dev/tty1 and also capture output to file

I want to display text output on the console that is always displayed on a small screen on my Raspberry Pi. The following code works for showing that text output: cd ...
1
vote
3answers
30 views

read -e in a sub script

Let's imagine that I have script1.sh and script2.sh with the following sources: Script 1: #!/bin/bash # script 1 echo "Doing some stuff..." bash script2.sh echo "Done" And Script 2: #!/bin/bash # ...
0
votes
2answers
41 views

Bash function for piping data into protected file [duplicate]

I wanted to create a .bashrc function that would simplify passing data to a write-protected file. function pipe { sudo bash -c "$1" } Unfortunately the command pipe echo something > ...
0
votes
1answer
42 views

Using echo to alter a files md5

I need to alter the md5 for some of my files, I was told to run the following echo >> /path/to/file.iso I was just wondering, What does actually do to the file. It seems to work and change ...
3
votes
2answers
152 views

Meaning of `cat /dev/null > file`

In a document created by a former coworker there is this command: cat /dev/null > /var/spool/mail/root It says next to it that it will clean out mailbox. Can someone please explain how/why ...
1
vote
1answer
60 views

Shell : while read line nested

I've two documents: doc1.lst and doc 2.lst I want to take the content of each line and put it as parameters for my SQL query. I tried something like this, please correct me file=doc1.lst ...
1
vote
1answer
23 views

Apply Escape Characters in Redirected Output

I'm running a program that prints lots of escape characters (like "Esc[1A", to move the cursor up one line), and trying to redirect the output to a log file. When I run the program without ...
4
votes
2answers
42 views

stdin 'hop' over process?

Is there a way that stdin can 'hop' over a process? For example, in the following command, cat file | ssh host 'mkdir -p /some/directory && cat > /some/directory/file' This will send the ...
2
votes
1answer
40 views

How can I redirect output files to a specific directory/folder

Suppose I have an executable in Unix. Suppose the name of the .exe file is myExe and it takes two parameters. I did not create this executable, this is a freely available one. myExe generates 4 ...
3
votes
1answer
34 views

Pipe command output to Yad and also log the output to a logfile

Need to have the process of command typically an update to be shown using yad and at the same time log all the output to a given log file set up. This is what I have apt-get update | yad ...
2
votes
2answers
109 views

Is it possible to send a HEREDOC over ssh to a remote host from inside a script running locally?

I essentially want to run a script on machine A which will SSH into machine B, execute commands on B, and return the output to machine A. So I am creating a csh script to do this, hopefully, if it's ...
1
vote
0answers
62 views

Why the output is not written to log from expect script

I am trying to write the output of the netcat command including the command also to a file by logging into remote servers. But it is not writing. What am I missing ? #!/usr/bin/expect -f set user ...
0
votes
1answer
38 views

explain this shell command with redirection and pipe

I can understand the statements like. bzip2 --version >/tmp/list_right 2>/tmp/list_error bzip2 --version >/tmp/list 2>&1 But I don't understand the statement: bzip2 --version ...
1
vote
0answers
73 views

Sed regex printing into a file.txt

I'm connected to a MQTT stream, and I filter out the data by entering : mosquitto_sub -d -t +/# 2>&1 | sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;p}" into the Ubuntu terminal. ...
21
votes
6answers
742 views

How to tell if output of a command or shell script is stdout or stderr

Let us say I run a command or shell script, and it gives me output. Without knowing the internals of this command or shell script, how does one determine if is the output was from stderr or stdout? ...
2
votes
1answer
94 views

Set bash script output to the line that called bash script

I've looked for the greater part of two hours trying to see if I could find a way to redirect the output of a bash script to the line that called the bash script. The best example I can use to ...
2
votes
1answer
69 views

Capture console output from existing process(es) to file [duplicate]

We have a requirement to troubleshoot an existing system running Busybox, we have Telnet access. It would be helpful to log the system's console output (ideally the last n lines of it) to a file for ...
0
votes
2answers
52 views

Unix how to loop through directories, send output to another directory with base name of input file

I am an infrequent user of UNIX, I'm sure this will be fairly trivial for any regular user so I appologize for that. I have the following code: for file in /home/sub1/samples/aaa*/*_novoalign.bam ...
10
votes
3answers
865 views

What does `1>>` and `2>>` mean in a bash script?

I have the following bash script, from what I understand >> is used to append the output of a command to an existing file instead of overwrite, but what is it doing in this case? This script is ...
0
votes
1answer
72 views

Ambigous redirect done >$2

I have finished my bash script but I am still getting two errors. I've also searched for related issues but none worked: #!/bin/bash avem_element () { local e for e in "${@:2}"; do [[ "$e" == ...
7
votes
2answers
279 views

How do redirection in a symbols work in a sequence?

I have file1, file2, file3. file1 contains 1 file2 contains 2 file3 contains 3 I use command cat file1 > file2 > file3 Results in: file1 1 file2 (contains nothing) file3 1 Why ...
0
votes
2answers
43 views

redirect output from interface?

I am echoing an AT command to a modem interface (/dev/ttyUSB3) and the command runs successfully. For instance the below command works and has an output of OK: echo -e "ATZ\r" > /dev/ttyUSB3 I ...
0
votes
1answer
59 views

“Sudo” prefixed command doesn't work; without sudo does.

I suspect this has been answered before, but I don't know what this is called, so I can't really search for it. How come this works : $ grep H=p <(udevadm info /dev/ttyUSB0) E: ...
4
votes
2answers
195 views

Appending works without >> when redirecting standard output and error

I have a file test.txt and have no file named test. When I tried ls test test.txt > new 2>new I was expecting new to be overwritten since >> is not used. But in the output file I got ...
1
vote
1answer
110 views

Correct syntax to avoid bash 'ambiguous redirect' message

I am trying to execute a command which accumulates stdout into an existing file and sends the error messages to another using the command below. commmand >> /home/user/accumulate_output.log ...
1
vote
2answers
140 views

Multiple File Redirection with awk and find

I have some files in a directory. And I want to add some lines at top and end of file using awk. Example: My awk command: awk 'BEGIN { print "line1\nline2" } { print $0 } END { print "line3\nline4" ...