Hot answers tagged

30

vipe is a program for editing pipelines: command1 | vipe | command2 You get an editor with the complete output of command1, and when you exit, the contents are passed on to command2 via the pipe. In this case, there's no command1. So, you could do: : | vipe | pandoc -o foo.pdf Or: vipe <&- | pandoc -o foo.pdf vipe picks up on the EDITOR and ...


18

You can do this from within Vim: :w !pandoc -o file.pdf Or even write the buffer into a complex pipeline: :w !grep pattern | somecommand > file.txt And then you can exit Vim without saving: :q! However, considering your specific use case, there is probably a better solution by using vi as your command line editor. Assuming you use bash: set ...


10

Running in a pipeline Try: quickedit() ( trap 'rm ~/temp$$' exit; vim ~/temp$$ >/dev/tty; cat ~/temp$$ ) The key is that, to be able to use vim normally, vim needs stdout to be the terminal. We accomplish that here with the redirect >/dev/tty. For purposes of security, I put the temporary file in the user's home directory. For more on this, see ...


9

This is because the netcat command has not even started yet! The shell when trying to open the fifo for input will block. Try strace cat >fifo <fifo and you will see nothing. Instead use, for example, nc -k -l 4458 -v <>fifo >&0 which opens the fifo for read and write as stdin, and then dups it to stdout. Tracing the full bash ...


9

I'll suggest a named pipe. Create a pipe mkfifo p (call it whatever you want, if not 'p') Create a "reader" script that reads from the pipe and writes wherever you like Tell the monitoring program to write its logs to the named pipe Here's a sample reader script that reads from a named pipe 'p' and writes the data to an indexed 'mylog' file: #!/bin/sh ...


7

Building up on your SIGINT idea, here using SIGQUIT (Ctrl+\) to you can still use Ctrl+C to stop the whole thing: (trap '' QUIT; monitor_command) | ( trap : QUIT ulimit -c 0 # prevent core dump so SIGQUIT behaves like SIGINT # for cat n=0; while n=$((n+1)); file=output.$n.log; do printf 'Outputting to "%s"\n' "$file" cat ...


5

Eric Blake answered on the bash-bugs mailing list: jobs is an interesting builtin - the set of jobs in a parent shell is DIFFERENT than the set of jobs in a subshell. Bash normally creates a subshell in order to do a pipeline, and since there are no jobs in that subshell, the hidden execution of jobs has nothing to report. Bash has code to ...


5

Just use sed p. echo foobar | sed p You don't need cat, either: sed p input.txt # or sed p input.txt > output.txt Explanation p is the sed command for "print." Print is also sed's default action. So when you tell sed explicitly to print, the result is that it prints every line twice. Let's say you wanted to only print lines that include the ...


4

Make sure that vim is set as your default editor (e. g. export EDITOR=vim in your .bash_profile or .bashrc. Then, at any prompt, you can type Ctrl-X followed by Ctrl-E. This will open your current command line in your configured editor (e. g. vim). Make your edits, save and exit, and the command will be executed as though you had typed it on the command ...


4

Instead of >(cmd), assuming it's cmd's stdin you wish be a tty instead of a pipe, you could try and use: >(socat -u - exec:'cmd',pty) socat would use a pseudo-tty pair and have cmd's stdin connected to the slave part ([ -t 0 ] would then return true). The pseudo-terminal will be put in raw mode, so the line discipline should not interfere with the ...


4

That's basically a duplicate of my answer on SO. However, since nobody mentioned the stdbuf command here, I felt like I should add that here as well. =============== Basically a process that reads from a pipe can consume the data byte by byte as soon as they are available in the pipe. However, as long as the programs are using std io functions of the libc, ...


4

The pipes connect the output or the left command to the input of the right command. This has nothing to do with the length of the stream. However, each command in the pipeline still has it's own buffering rules. If you don't trigger them in each command you won't see them on the final output.


3

This isn't possible with standard UNIX/POSIX facilities. Your imperfect options are: Just use a shell script, and have the "opening" application (or your shell) execute it instead of opening it for reading. Some apps may support doing this, otherwise you'll have to resort to a shell script wrapper. Use a fifo, and write a daemon that writes to it. This of ...


3

You could use the -u option of sed to minimize buffering: cat | sed -u '' | sed ''


2

espeak supports using --stdin to read from a pipe, so one option would be to change your function call to use that instead of parameters, and pipe the printf output into your function: speak(){ espeak -a 200 -s 130 -v la --stdout --stdin | aplay; } printf '%b\n' "$(cat joyPhrase)" | speak Or you can pass the output of your other command to speak's ...


2

The test command runs isatty(fd) to check whether a descriptor is related to a TTY. isatty(3) is a C library function that checks whether a file descriptor allows to send terminal ioctl(2) calls to the descriptor. You therefore cannot fake the result unless you use LD_PRELOAD= to overwrite the isatty() function in the shell.


1

One example: $ echo jeff > jeff $ echo not > not $ echo 's/jeff/not/' | sed -i -f - * $ cat jeff not For more information on what standard shells should do with filename/pathname expansion (globbing), see: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_06 where it says: After field splitting, if set -f is not ...


1

You may be after: \e[32m style escape sequences in your string such as echo -e "Doing ls\n\e[32m$(ls --color=never)\e[33m ^^^\n \e[36m ls \e[39m output" printf "\e[35mHello\e[41mWorld\e[0m!" There are a few articles & listings of colours including: http://www.bashguru.com/2010/01/shell-colors-colorizing-shell-scripts.html?m=1


1

Finally I have figured out what the problem is! It is most likely because of an IP Conflict ._. Sorry to bother you guys. After I have switched from fix IP to DHCP, no packets loss in ping anymore. Thanks guys. Lesson learned.


1

You could probably use less and save from there by typing s then the file name you want to save to, then Enter. From How do I write all lines from less to a file?.


1

You can escape the double quotes printf '%b\n' "\"$(cat joyPhrase)\"" On my machine $ echo this is a file >> testfile $ printf '%b\n' "\"$(cat testfile)\"" "this is a file" Instead of using cat, you can use the redirect: $ printf '%b\n' "\"$(< testfile)\"" "this is a file"


1

perl -00 -n -e 'print if (m/blue/i && m/green/i && m/yellow/i)' filename This uses perl's paragraph-reading mode (-00) to print only paragraphs containing all three words (with case-insensitive matches). a 'paragraph' is one or more lines of text, separated from other paragraphs by at least one blank line. e.g. I saved the text of your ...



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