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

learn more… | top users | synonyms (1)

2
votes
3answers
63 views

Using a command's output to determine the name of the file to redirect output to

I want to run smartctl -a, and use the device serial number from that output as the name of the file to store the output in. I know this can be done by invoking smartctl twice, and slicing up the ...
0
votes
0answers
20 views

how to route traffic on port to ip:port on linux?

I'm trying to route all traffic on port udp 5000 to udp 192.168.0.1:12333 with the following command: $ iptables -t nat -A PREROUTING -p udp -m udp --dport 5000 \ -j DNAT --to 192.168.0.1:12333 ...
7
votes
3answers
306 views

output to file, then use file for input

Is there a shorter way of writing this? Basically output a command to a file, then use the file as input for the next command. I also want to keep the file to view afterwards. cmd1 > verylong.txt; ...
1
vote
2answers
48 views

Redirect stdin and stdout to ports

I'd like to take a program P that reads from stdin & writes to stdout, but connect it to nc or whatever such that it reads from a certain port and outputs to another port. # The reading is easy, ...
3
votes
2answers
49 views

Syntax error: word unexpected on io redirection on file descriptor ≥10

I have the following shell script on debian 7: #!/bin/sh case "$IFACE" in lo) # The loopback interface does not count. # only run when some other interface comes up exit ...
1
vote
1answer
20 views

Capturing data from a Fluke 1620a via netcat

I am trying to pull temperature and humidity data from Fluke DewK 1620a thermo-hygrometers and write the temp/humidity readings to a log. I can connect to the device via netcat with a simple 'nc ...
1
vote
1answer
26 views

redirect to the same file as the source file processed by the command [duplicate]

Redirection is not allowed here. Is cat not allowing? But isn't redirection independent of any command running with it? $ cat bk > bk cat: bk: input file is output file Why does the following ...
-1
votes
3answers
53 views

what is the use of '<<' redirection? [duplicate]

I am looking for an example of << redirection because i don't understand it well. I know < is for sending the contents of specified file to be use as standard input like : cat < file.txt ...
3
votes
3answers
67 views

How can I base the file name off of an already existing variable?

I'm using this to delete lines that don't match a pattern: $ egrep "pattern1|pattern2|pattern3|pattern4|pattern5" But now I need to do it automatically, so I'm setting a variable like this: $ ...
4
votes
3answers
302 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
52 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 ...
1
vote
2answers
91 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
62 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" ) >> ...
27
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
80 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
118 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
46 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 ...
5
votes
1answer
269 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
52 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
45 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
38 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
113 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
29 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
47 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
74 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
110 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
19 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
47 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
171 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
62 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
298 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
114 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
63 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
39 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
72 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
216 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
179 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
128 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
37 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
55 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
463 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
159 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
194 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
97 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
75 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
73 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
290 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
406 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
107 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
145 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 ...