New answers tagged

0

I used sed because it can be used with sudo. For example: sudo sed -i '$ a text to be inserted' fileName.file the alternative is very ugly like : sudo bash -c "echo a text to be inserted >> fileName.file" and even uglier when done with ssh.


1

You're discarding the error output from wc, not from hdfs. See my answer to something quote similar on serverfault.


0

Just in case anyone else has this issue: I simply waited a bit longer instead of killing the program immediately, and it worked. Just ignore the scary messages.


2

You could use the --filter option of split to invoke zip on each split file gunzip -c file.gz | split -l 500 -d -a 4 - pref_ --filter='zip $FILE'


0

sed has the w command that might do what you require: w filename Write the current pattern space to filename. sed 'w file' on its own will have the same effect as tee file. If there are other sed commands, put the w last: sed 's/This/That/;w file' However, this won't be affected by the -n/--quiet/--silent option. That only suppresses the ...


1

tee and > can be used for data redirection because these are meant to be used for data redirection in linux. sed on the other hand is a stream editor. sed is not meant for data redirection as tee and > meant to be. However you can use conjunction of commands to do that. use tee or > with sed sed 's/Hello/Hi/g' file-name | tee file or sed ...


2

The operator < is most commonly used to redirect file contents. For example grep "something" < /path/to/input.file > /path/to/output.file This would grep the contents of input.file, outputting lines containing "something" to output.file It is not a full 'inverse' operator of the > operator, but it is in a limited sense with respect to files. ...


0

It redirects the file after < to stdin of the program before <. foo < bar will run the program foo using the file bar as its stdin.


0

Use this: yum repolist all --color=never > repolist.txt No matter what, you are actually only getting three, not four columns of output. The install count is part of the status column. The resultant file appears thus: Loaded plugins: fastestmirror, presto Determining fastest mirrors * base: centos-distro.cavecreek.net * epel: mirror.oss.ou.edu * ...


0

&<- closes the file descriptor. But more fundamentally, searching for those little "&" atoms on Google can be painful! See this site on bash redirection for background info.


1

May be this list helps: <&(Digit) Duplicates standard input from the file descriptor specified by the Digit parameter >&(Digit) Duplicates standard output in the file descriptor specified by the Digit parameter <&- Closes standard input >&- Closes standard output


2

Rather search through manual pages (man bash is your friend). Such special characters are hard to find in google. Basically you end up with this section: Duplicating File Descriptors The redirection operator [n]<&word is used to duplicate input file descriptors. If word expands to one or more digits, the file descriptor denoted by n ...


0

Use screen's log command (!) Since the process is running in a screen session already it's just a matter of telling screen to log the output of that window: Switch to the script's window, C-a H to log. Now you can : $ tail -f screenlog.2 | grep whatever From screen's man page: log [on|off] Start/stop writing output of the current window to a ...


0

Not sure what this is supposed to achieve but here is a solution that does exactly what you're doing without using an intermediate file: #!/bin/bash # prevent LF from being removed export IFS=' ' output=`process1` echo $output | head -n 3 echo $output | tail -n +4 | head -n -4 | process2 # producing output echo $output | tail -n 4


0

I think you can just pipe them : to process every line from process1 except the first and last, say, 3 lines: process1 | tail -n +4 | head -n -3 | process2


0

Thanks to Jeff Schaller's answer, I ended up with something like this, which basically does what I need, let's call it reader.sh: #!/bin/sh INDEX=0 LOGNAME="$INDEX.log" switchlog() { local custom_name read -p "Add log name: " custom_name INDEX=$((INDEX+1)) LOGNAME="$(printf "%03d" $INDEX).$custom_name.log" echo now writing to $LOGNAME } trap ...


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 ...


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 ...


0

Without knowing more about your "request" its not really possible to answer. If it were based on file size or interval, then rotatelogs (which should come bundled with Apache httpd) would work.


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?.



Top 50 recent answers are included