Tag Info

New answers tagged

2

It's easy to dynamically build the string and eval it: eval "$(echo -n 'pr -mt '; while read ext; do echo "<(ls -1 *.$ext)"; done < list |tr '\n' ' ' )" where list would be the file (possibly a fifo) representing the list of extensions you want to build the command from. <() essentially creates unnamed FIFOs. An eval-less alternative might be ...


0

If I understand your demands correct this does what you expect: awk '/ddddddddddddddd/,/hhhhhhhhhhhhhhh/ { print > "excerpt" } 1' infile | tail -f awk works as filter on file "infile"; it prints everything in between the given patterns into a file "excerpt", and it also prints every line to standard output, which is then processed by tail -f as usual. ...


0

Maybe you can use awk's range patterns here: tail -f logfile | awk '/ddddddddddddddd/,/hhhhhhhhhhhhhhh/' If you need to circumvent the SIGPIPE problem you can use socat instead of tail for the job: socat -u file:logfile,ignoreeof "system:'stdbuf -o0 awk /ddddddddddddddd/,/hhhhhhhhhhhhhhh/'" > logfile.new


3

This is exactly what retail does. retail is tail with regular expressions, a tool I wrote for exactly the use case you have here. In your case, you'd use: retail -f -r ddddddddddddddd -u hhhhhhhhhhhhhhh logfile > log.tmp -f is the standard tail -f option. -r takes a regular expression to use to start the range of lines to include, and -u takes a ...


9

The "Network is not reachable" message is printed to stderr, not stdout, so it isn't captured by your substitution ($(ping ...)). You need to redirect stderr to stdout when running ping, not when you log: print_and_log "$(ping -c10 "$i" 2>&1)"


5

You could try something like this: exec 9>&1 OUTPUT=$(grunt test | tee /dev/fd/9) exec 9>&- It copies the current stdout to file descriptor 9, uses tee to replicate grunt's output to that file descriptor, then afterwards closes the temporary file descriptor.


3

2> is not an operator in tcsh, you're using the > operator and passing 2 as an argument to vi. This appears to be okay since both --xxx and --version exit vi. From tcsh(1): > name >! name >& name >&! name The file name is used as standard output. If the file does not exist then it is created; if ...


7

This inconsistency is in fact the first reason in the list of reasons why csh programming is considered harmful. Or what if you just want to throw away stderr and leave stdout alone? Pretty simple operation, eh? cmd 2>/dev/null Works in the Bourne shell. In the csh, you can only make a pitiful attempt like this: (cmd > /dev/tty) ...


5

The << redirection operator introduces a "here document": the text fed into standard input comes just after the redirection. Here's an example: grep Hello <<EOF This line won't appear Hello this one will Hello again EOF All the text between <<EOF and EOF is fed into grep. EOF isn't special here, the shell takes the word given just after ...


3

This operator is used for multiline redirect. See below for example program <<KEYWORD line1 line2 line3 KEYWORD The above send line1, line2, line3 strings, delimited with newline You should not have KEYWORD (can be any other word) in the text. And last line with KEYWORD should start from begin, no space, no tab, etc


5

For the shell command cat <file.txt: The redirection operator < causes the shell to open file.txt for reading. The shell executes the cat command, with its standard input connected to file.txt. The cat command reads from its standard input (so file.txt) and copies the content to its standard output. So the shell is the one opening the file, but the ...


-1

You're correct. While this won't matter in many situations, if the shell and the process have different permissions it can. If the process you're calling has elevated privileges (such as sudo or setuid), then it can use those privileges to open files that your shell might not be able to. $ sudo cat < /etc/shadow | wc -bash: /etc/shadow: Permission ...


2

The terms you need in order to use some google-fu are 'redirection' which is what you're doing in process < input.txt and 'piping' which is what you're doing in cat input.txt | process Once you know this, you can find articles like this one http://askubuntu.com/questions/172982/what-is-the-difference-between-redirection-and-pipe which answers your ...


3

The redirection to file.txt at the end of your paste command is truncating your file before paste has a chance to read it. Try echo 2 | paste file.txt - > file2.txt or if you have sponge installed echo 2 | paste file.txt - | sponge file.txt


0

Try vim-way: $ ex -s +'%!cut -c 1-10' -cxa file.txt This will edit the file in-place (so do the backup first).


0

I'm not clear if you get one result per read?, or if you get a stream of results. I think you're saying one request -> one reply. And you never gave a hexdump or anything of the output, but it looks like the line endings are probably CR-only, not DOS CR-LF or unix LF. (That's why your prompt overwrites the output after netcat.) I did find the manual: ...


0

This is probably not the prettiest solution, but you can do something like: cat file.txt | tee -a stdin.txt | ./program | tee -a stdout.txt You could use the same file in both tees, but your input and output might get mangled and unreadable.


0

You already have the stdin log: that's your file. Otherwise (not sure if this is what you're trying to accomplish), if you rather want a log containing both the stdin and stdout interspersed, you could modify your program to send the lines from stdin to stdout as they're read, before they are processed.


0

Here is a post summarizing Unix output streams: http://www.devcodenote.com/2015/04/unix-output-streams.html A snippet from the post: There are 3 standard output streams: STDIN - Standard Input - Writes from an input device to the program STDOUT - Standard Output - Writes program output to screen unless specified otherwise. STDERR - Standard Error Output - ...


0

If you want the output of the program that you tell xterm to run, xterm -hold -e " program arg1 arg2 arg3 | tee ~/log.txt" So for instance , in my Ubuntu I'd run from gnome-terminal something like xterm -hold -e " firefox | tee ~/log.txt" There's also an option to log errors with xterm -hold -e program 2> errors.txt which redirects any errors that ...


14

Normally xargs will put several arguments on one command line. To limit it to one argument at a time, use the -n option: $ seq 3 | xargs -n 1 echo 1 2 3 Documentation From man xargs: -n max-args Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s ...


5

A bit more research revealed the answer from Make xargs execute the command once for each line of input: $ seq 1 3 | xargs -L 1 echo 1 2 3


3

while …; do echo "$fname" >&1 done > logfile The standard output of the echo command is redirected to its standard output. In other words, >&1 is a no-op. The 1 in >&1 designates file descriptor 1 of the command where it is used, not of some mysteriously-chosen outer scope. To redirect to a file that is available at an outer ...


3

It's because your input stream is feeding both read. You're almost right, so maybe it's a typo (you just forgot to give to right FD to your second read) : while IFS=',' read a b c; do read input <&3 echo $input done 3<&0 < input.csv >> output.txt


2

Your while loop is non-interactive, thus doesn't have a tty. You have to save your tty device before entering the loop. So you'd have something like: my_tty=$(tty) while read fname fpath dname dpath ; do echo "$fname" | tee ${my_tty} echo "$fpath" echo "$dpath" diff "$fpath/$fname" "$dpath/$dname" | tee ${my_tty} done > logfile



Top 50 recent answers are included