Tag Info

New answers tagged

1

I think, it's better to replace \n symbol to some other, and then work as usual: e.g. not-worked source code: cat alpha.txt | sed -e 's/a test\nPlease do not/not a test\nBe/' can be changed to: cat alpha.txt | tr '\n' '\r' | sed -e 's/a test\rPlease do not/not a test\rBe/' | tr '\r' '\n' If somebody don't know, \n is unix line ending, \r\n - windows, ...


0

What the guys mentioned is true but from the user's point of view there is only one difference: wget is used to download things curl is used to see/test what response you get from a machine For example wget http://www.google.com will download the HTML file located at www.google.com, while curl http://www.google.com will just print onscreen the ...


0

Short and sweet, shell only solution: convertB_human() { NUMBER=$1 for DESIG in Bytes KB MB GB TB PB do [ $NUMBER -lt 1024 ] && break let NUMBER=$NUMBER/1024 done printf "%d %s\n" $NUMBER $DESIG } It doesn't show the decimal potion. The let VAR=expression is Korn-ish. Substitute with VAR=$(( expression )) for Born-again-ish.


1

Another perl: $ perl -pe '$_ = pack("i", $_)' file i represents signed integer value (which is represent at least 4 bytes, depend on local C compiler). Use l option like @St├ęphane Chazelas's answer for always use 32-bit.


4

perl -pe '$_=pack"l",$_' < infile > outfile Uses the local endianness. Use l> instead of l for big-endian, and l< for little-endian. See perldoc -f pack for more info. Note that it's l as in lowercase L (for long integer), not the 1 digit. $ printf '%s\n' 1234 -2 | perl -pe '$_=pack"l",$_'| od -vtd4 0000000 1234 -2 0000010 $ ...


1

Here is a hacked-up python script to do something like what you are requesting: #!/bin/sh ''':' exec python "$0" "$@" ''' KEEP = 10 MAX_SIZE = 1024 # bytes LOG_BASE_NAME = 'log' from sys import stdin from subprocess import call log_num = 0 log_size = 0 log_name = LOG_BASE_NAME + '.' + str(log_num) log_fh = open(log_name, 'w', 1) while True: line ...


1

The best I could find so far as an approximation that doesn't involve writing huge pieces of code is this zsh code: autoload zmv mycmd | while head -c20M > mycmd.log && [ -s mycmd.log ]; do zmv -f '(mycmd.log)(|.(<->))(|.gz)(#qnOn)' '$1.$(($3+1))$4' {rm -f mycmd.log.1 mycmd.log.50.gz; (gzip&) > mycmd.log.1.gz} < ...


5

You can get some of what you want via pipelog, which "allows for rotating or clearing the log of a running process by piping it through an intermediate which responds to external signals", e.g.: spewstuff | pipelog spew.log -p /tmp/spewpipe.pid -x "gzip spew.log.1" You can then get the pid from /tmp/spewpipe.pid, and: kill -s USR1 ...



Top 50 recent answers are included