Tag Info

Hot answers tagged

24

You might have a look at zgrep. >$ zgrep -h grep through gzip files usage: zgrep [grep_options] pattern [files]


19

wget -O - -o /dev/null http://google.com


18

Or use curl, where it's the default behaviour. curl http://www.google.com/ http://curl.haxx.se/


16

To do that, use one extra file descriptor to switch stderr and stdout: find /var/log 3>&1 1>&2 2>&3 | tee foo.file Basically, it works, or at least I think it works, as follows: The re-directions are evaluated left-to-right. 3>&1 Makes a new file descriptor, 3 a duplicate (copy) of fd 1 (stdout). 1>&2 Make stdout (1) ...


15

The tool to use is probably the windows ports of netcat.


15

While a zip file is in fact a container format, there's no reason why it can't be read as a stream if the file can fit into memory easily enough. Here's a Python script that takes a zip file as standard input and extracts the contents to the current directory or to a specified directory if specified. import zipfile import sys import StringIO data = ...


15

Edit: I ran this with your source file in my environment and have the following results: [root@xt ~]# time tiff2ps test.tif > test.ps real 0m0.795s user 0m0.659s sys 0m0.135s [root@xt ~]# time ps2pdf13 -sPAPERSIZE=a4 test.ps > test.pdf real 0m0.592s user 0m0.513s sys 0m0.075s [root@xt ~]# time tiff2ps test.tif | ps2pdf13 ...


12

Similiar to other answers, but: lsof | grep 90222668 Will show you both ends, because both ends share the 'pipe number'.


11

You can use xargs with -n1 to run a command once for each piped argument $some_command | xargs -n 1 touch In the case of touch however which accepts multiple arguments touch `$some_command` will probably work for you.


11

You probably want sed 's/exp1/exp2/g' foo.txt > foo2.txt Read more at Sed tutorial, Another tutorial, and A small tutorial at Linux HOWTOs


11

You can use pv to do this e.g. pv file | processor_application As pv passes it's stdin directly to it's stdout you don't need to use cat. Edit As your program is already running then find the PID of the cat process and then look at the contents of /proc/<PID>/io which will tell you how many bytes it has written - wchar.


11

You do not need to use xargs, because find can execute commands itself. When doing this, you do do not have to worry about the shell interpreting characters in the name. find /path/to -name "*.html" -exec grep -l "rumpus" '{}' + from the find man page -exec command {} + This variant of the -exec action runs the specified command on the selected ...


11

You can use the -d option in curl with a @- argument to accept input from a pipe. You will need to construct the key-value pairs yourself. Try this: echo "time=`uptime`" | curl -d @- http://URL The backticks (`) denote that the enclosed command (in this case uptime) should be executed, and the backtick-quoted text replaced with the output of the executed ...


10

Use find ... -print0 | xargs -0 ... e.g. find /path/to -name "*.html" -print0 | xargs -0 grep -l "rumpus" from the find man page -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that ‘-print’ uses). This allows file names that ...


10

The zgrep program exists for this specific purpose. http://linux.about.com/library/cmd/blcmdl1_zgrep.htm


10

This is unlikely to work how you expect. Zip is not just a compression format, but also a container format. It rolls up the jobs of both tar and gzip.bzip2 into one. Having said that, if your zip has a single file, you can use unzip -p to extract the files to stdout. If you have more than one file, there's no way for you to tell where they start and stop. ...


8

Try using sponge from moreutils like this: sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd It collects the whole input before writing to it's output.


8

Kyle's Unix/Linux command does the job of switching the STDERR with the STDOUT; however the explanation is not quite right. The redirecting operators do not do any copying or duplicating, they just redirect the flow to a different direction. Rewriting Kyle's command by temporary moving the 3>&1 to the end, would make it easier to understand the concept: ...


8

$ my_command | tail -n +3 In this case, the +3 means "start output at the third line of the file".


8

Absolutely! Pipe Viewer does exactlty that. Just insert it in your pipeline: cat myfile | pv | processor_application You can optimize away the cat in the above example: pv myfile | processor_application Which has the advantage of providing an actual progress indicator, since pv can determine the size of the input directly. If you do use pv in the ...


8

Have you tried $ python example.py | bash It ought to work, as it's a common enough trick. For example, the monitoring tool munin has a node configurator (munin-node-configure) that tells you what plugins you can run, and then takes a --shell flag that makes it spit out a bunch of ln -s commands to link in the plugins, when piped directly to bash. There ...


7

The latter; it makes sure STDOUT and STDERR of the original command go to the same fd, then feeds them jointly into tee. In the former case, it's the STDERR of the tee command that you'd be joining with its STDOUT.


7

Use pv the pipe viewer. It's a great tool. Once you know about it you'll never know how you lived without it. It can also show you a progress bar, and the 'speed' of transfering.


7

You usually are only asked if you want to connect when ssh is performing host key checking. Instead of trying to disable by using expect or a pipe, perhaps you could just disable it in your ssh configuration. Add StrictHostKeyChecking no to your ~/.ssh/config, and ssh will no longer ask you if you want to connect, it will just connect.


7

Try psql ... | less -S The -S option to less enables horizontal scrolling instead of line wrapping.


7

I only use for ... do ... done for very simple cases. For more complicated/dangerous scenarios: command | sed 's/^/touch /' This does nothing but prints intended commands. Review the results, then perform the same thing piping to sh -x (the -x flag is for debugging): command | sed 's/^/touch /' | sh -x


6

I would guess sed still might create the temp file, but the following might do what you want? (Using strace on this might show you if sed creates a temp file or not). sed -i '/bar/!d' foo.txt The exclamation inverts the match, d is for delete, so this removes all lines that don't have bar in them.


6

What you want to do is, make unzip take a ZIPped file on its standard input rather than as an argument. This is usually easily supported by gzip and tar kind of tools with a - argument. But the standard unzip does not do that (though, it does support extraction to a pipe). However, all is not lost... Look at funzip manual page. funzip without a file ...


6

There are other methods you can use instead of wget and curl: You can use lynx: # lynx -source http://www.google.com w3m: # w3m -dump_source http://www.google.com and libwww-perl comes with a handy program called GET (as well has HEAD and POST, which do what you think they do) # GET http://www.google.com


6

mysqldump dbname | ssh root@remoteserver.com "mysql -D dbname" that should work :-) Set up keys between the systems as well so you can do so w/o needing a login/pass :-)



Only top voted, non community-wiki answers of a minimum length are eligible