Tagged Questions

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

learn more… | top users | synonyms (1)

4
votes
3answers
246 views

Hide ouput of bash while running automated script.

I have a couple of scripts in my bash file, that should do certain tasks, say like ... #!bin/bash yum -y update service restart nginx yum install atop cat /var/log/somelog.log > ...
1
vote
2answers
40 views

Combination of echo, pipe and cat

I have a file name called temp.csv in my script one of the intermediate step is echo "some info" > final.csv | cat temp.csv >> final.csv at times the file final.csv is created without ...
0
votes
2answers
52 views

double grep on tail -f gives no output

If I follow a file somehow like this: tail -f /var/log/syslog|grep s I see all lines containing an "s" Why does this not give any output, if I grep it again to the same "s"? tail -f ...
0
votes
3answers
49 views

Pipe/redirect a group of commands

I currently use the following setup to redirect the output of multiple commands: echo "Some normal commands" ( echo "Error: something happened" echo "Warning: this incident will be logged" ) >> ...
25
votes
2answers
2k views

How does `cat <> file` work?

cat < file prints the contents of file to stdout. cat > file reads stdin until Ctrl+D is detected and the input text is written to file. cat <> file, at least in my version of Bash, ...
0
votes
1answer
49 views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
3
votes
3answers
103 views

Dash equivalent of self-redirection of script output

In Bash you can redirect all future stdout output of the currently running script. For example with this script, exec > >(logger -t my-awesome-script) echo 1 echo 2 echo 3 This will end up in ...
0
votes
0answers
40 views

Why is a here-string command substitution considered as a single line?

I'm experimenting with while read syntax and there is a thing I don't understand. The most basic scenario which reproduces the problem is the following: a bash script a.sh calls another script b.sh ...
4
votes
1answer
260 views

Why does “cat /tmp/out1 > /tmp/in2 &” appear as “bash” with the “ps” command?

Consider: mkfifo /tmp/out1 mkfifo /tmp/in2 cat /tmp/out1 > /tmp/in2 & When I run ps it appears as bash in the CMD section. Why?
1
vote
1answer
43 views

Pipes & redirection binding precedence with disjuncts, conjuncts etc?

I know of the relative binding precedence of operators ‘;’, ‘&’, ‘&&’, or ‘||’ http://www.gnu.org/software/bash/manual/bashref.html#Lists but when pipes come into the picture along with ...
2
votes
2answers
37 views

saving the output of command line in a text file?

I am using the following command line to analyse data: unpackdcm -scr ${in} -targ ${out} This command is printing on the screen status and description about the progress in the job. In order to ...
1
vote
1answer
29 views

Redirect output to stdout and pipe to a binary

I have a nice PS1 line in my .bash_profile, and I want to copy it to another machine. So I want to view it AND copy it to my clipboard. I can't figure out how to string the commands to do this ...
3
votes
2answers
94 views

How can a bash script write its standard output from within a pipeline? [duplicate]

I have a bash script that calls a function. The function, amongst other things, executes a pipeline that sinks its output. To simplify it, here is a contrived example: #!/bin/bash func() { ls "$@" ...
0
votes
1answer
23 views

UNIX stdout redirection

I've written a script and I want to direct the console output to a file, so I use this command: ~/simplesim-3.0/sim-cache -cache:dl1 dl1:1:64:2048:f -cache:il1 il1:1:64:2048:f \ -cache:il2 dl2 ...
0
votes
3answers
29 views

Redirect stderr and stdout to another file descriptor

exec 6>&1 will copy file descriptor 1 onto 6. But how can I copy both stderr and stdout (1 and 2)to file descriptor 6 ?
4
votes
3answers
60 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...
2
votes
1answer
98 views

Writing to an interactive prompt

I’m using the ftp command line tool and want combine scripted input with user input. With only user input the prompt looks like this: ftp> But when I try to insert some input with a script, like ...
1
vote
1answer
17 views

ag output appears different in the terminal vs when piped to a file

When I run the ag command to search text files, I get output that looks like this on the command line (full results not shown): ❯ ag dependency 140317155505.md 27:The Bundler dependencies API ... ...
-1
votes
1answer
42 views

Redirect a directory as input to a script and output to a file

I want to use a directory name as a parameter for a pre-made script. Then the output goes into a newly made file in the home directory. It involves pipe/redirection. How do I do that? read dir $dir ...
4
votes
2answers
102 views

How to capture ordered STDOUT/STDERR and add timestamp/prefixes?

I have explored almost all available similar questions, to no avail. Let me describe the problem in detail: I run some unattended scripts and these can produce standard output and standard error ...
0
votes
6answers
57 views

What are some practical uses of STDIN redirection? [closed]

I am having a very difficult time trying to think of a single practical use for STDIN redirection. cat < /etc/passwd is an example of STDIN redirection, but it is silly in the same way as a useless ...
7
votes
4answers
279 views

Can I specify a redirected input before a compound command?

Bash lets you specify a redirected input before a command: $ <lines sed 's/^/line: /g' line: foo line: bar Bash also lets you redirect input to a compound command like a while loop: $ while ...
1
vote
2answers
89 views

How to grab output from command in shell script [duplicate]

I'm trying to write a shell script in RHEL which will execute grub-md5-crypt and the user will type their password. Now the problem is how can I grab the encrypted md5 hash displayed to the user in ...
2
votes
2answers
57 views

Should I use piping or redirection for input to 'sort'

I want to do awk -F "," '{print $1 }' inputfile1.txt | sort -u > distinctOutput.txt Is this good performance-wise ? Or should I redirect / use a temp file since I think it is better to make sort ...
1
vote
1answer
33 views

fuser output looks ambiguous

I am using fuser the output is like this: $ fuser / /: 1354rc 1362r 1370rc 1371rc 1395rc 1399rc 1403rc 1410rc 1414rc 1428r 1451rc 1458rc 1470rc 1472rc 1477rc 1480rc ...
-4
votes
1answer
68 views

UNIX homework question regarding piping output, I don't understand what it's asking?

Basically, I need to come up with a command that sends the contents of a file xxx into a program yyy, then the output is piped to the input of another program zzz, where the output is appended to a ...
11
votes
2answers
211 views

Why does cat x >> x loop?

The following bash commands go into an infinte loop: $ echo hi > x $ cat x >> x I can guess that cat continues to read from x after it has started writing to stdout. What is confusing, ...
1
vote
1answer
113 views

How do I Nohup an interactive shell-script?

My Script is having 2 command-line arguments and then just couple of questions, after these questions the script will run for itself, I'm able to pass the command-line argument by just doing, ...
1
vote
2answers
109 views

Process substitution with input redirection

I am trying to understand input redirection in combination with process substituation. I am using bash 3 An example with tr is the following $ tr "o" "a" <(echo "Foo") tr: extra operand ...
1
vote
1answer
28 views

Cannot redirect output from sed

I'm piping output from clock through sed to remove leading zeroes from numbers. It looks like this: clock -sf 'S%A, %B %d. %I:%M %P' | sed 's/\b0\+\([0-9]\+\)/\1/g' That works fine and produces the ...
0
votes
1answer
50 views

Bash STDERR still appearing after redirection [closed]

I am trying to parse the output of yum check-update in Bash 4 (Red Hat) and want to skip the first line that states: 'This system is not registered to Red Hat Subscription Management. You can use ...
5
votes
2answers
458 views

Is there any way to read lines from command output?

I have a pre process command to output a file ./preprocess.sh > preprocessed_file and the preprocessed_file will be used like this while read line do ./research.sh $line & done < ...
1
vote
3answers
98 views

How to send a output of unix command from one server to another server?

How to redirect the output of a unix command from one server to another server. I should be able to send the unix command's output from server-1. Then I should be able to receive the output in ...
3
votes
4answers
184 views

Redirect and pipe output

rpm -qa > file | wc -l returns 0. What am I doing wrong? I think it is clear what my goal is, but it isn't working. Is this a job for xargs or tee?
1
vote
3answers
66 views

How can I pipe data over network or serial to the display of another linux machine?

I have a second monitor that I'd like to use for a text-based debugging log and/or console. I don't want to have it as part of my GUI / "desktop" / main system. I have this display connected to an ...
1
vote
1answer
70 views

Why doesn't this piped script work?

#!/bin/bash rm out mkfifo out nc -l 8080 < out | while read line do echo hello > out echo $line done If I browse to the IP of the machine this script is running on (using port ...
4
votes
2answers
69 views

Inconsistent redirection behavior ssh interactive vs commands

These work, ssh remote 'echo hi > hi.txt' echo hi | ssh remote 'cat > hi.txt' but this does not work ssh remote sh -c 'echo hi > hi.txt' I expected to produce a file on remote named ...
4
votes
4answers
285 views

A command that generates both standard error and output

I want to do some troubleshooting on my bash script. Is there a short and simple command that generates both stdout and stderr so that I can use 2>&1 on it? Sorry if this looks trivial, but I ...
4
votes
3answers
378 views

pipe line with non-deterministic output

I have happened upon a command that sometimes works and sometimes does not, even when executed multiple times in rapid succession in a bash shell (I have not tested the behavior in other shells). The ...
0
votes
3answers
101 views

What does running “< ./somefile.txt” in shell do?

So I just executed < ./somefile.txt in a shell, and it doesn't appear to do anything (the text file has valid linux commands). So where are the contents of the text file being redirected to? I'm ...
1
vote
1answer
97 views

How to redirect per-CPU top output to file?

I want redirect top output to a file, but I am interested in the per-CPU usage. Doing just #I only want to see processes belonging to myuser top -b -d 1 -u myuser > top.txt gives me stats ...
1
vote
1answer
63 views

Why do I get “Permission denied” when redirecting the output of sudo echo “xyz” to a file? [duplicate]

Why do I get -bash: test: Permission denied when I run sudo echo "xyz" > test The directory permissions are: drwxr-xr-x 3 root root 4096 2014-08-05 16:26 I have no problem creating a ...
1
vote
2answers
44 views

awk - read program AND input from the standard input?

Is it possible for awk to read the program and the input from the standard input? I would like to be able to pipe a file to the following function. process_data () { awk -f - <<EOF {print} ...
0
votes
0answers
178 views

start-stop-daemon doesn't stop programs which redirect stdout/stderr

I just discovered, that start-stop-daemon doesn't work well with programs redirecting their stdout/stderr: # cat /root/_/1.sh #!/usr/bin/env bash set -eu cmd="~yuri/_/${2:-1}.sh" if [ "${3:-}" = ...
5
votes
1answer
67 views

Is it possible to use multiple here-docs in bash?

Can one use multiple here-docs to provide input to a command in bash? $ cat <<<foo <<<bar bar $ cat <<EOF1 <<EOF2 > foo > EOF1 > bar > EOF2 bar Obviously, ...
7
votes
1answer
62 views

How can I send reads and writes on a single file descriptor to different places?

I have a Linux executable foo that reads input from fd 0 and writes output to fd 0 (not fd 1). This works just fine for interactive use in the terminal. From the shell command line, how can I execute ...
-1
votes
3answers
261 views

cat /dev/null emptied my log file but size did not change

I'm quite new to Unix. Using Solaris 10 I faced the below issue. There is a large log file with size 9.5G. I tried to empty the file using the below command. # cat /dev/null file_log.txt By doing ...
3
votes
1answer
60 views

Does cat never read from terminal?

Chapter 43. Redirecting Input and Output of Unix Power Tools, Third Edition has to say this about cat command: Standard input (stdin) normally comes from your keyboard. Many programs ignore ...
3
votes
2answers
79 views

Decoding “prog > file 2>&1”

I am having some difficulty understanding the construct prog > file 2>&1. I have read that it means "Send stdout and stderr to file". But my question is how? I understand that prog > ...
4
votes
2answers
123 views

How to redirect stdout to a file and read from the same file simultaneously with another task?

I want to run a task (which takes quite a long time) remotely in Ubuntu Linux Bash via nohup and redirect stdout to a file, e.g.: nohup task > out.txt & From time to time I would like to ...