Tag Info

New answers tagged

1

Here's a one liner of the iw command that have the same output as you. iw dev wlp1s0 link | grep 'SSID:\|signal' | awk '{printf "%s ", $2$3}' My output: ZyXEL-AP-2,4GHz -46dBm


0

Something like that ? iw dev wlp1s0 link | grep -E '^\s*(SSID|signal):\s' | sed -r 's/^\s*(SSID|signal):\s//' | awk '{printf $0}' grep will accept (SSID|signal): so it will match both SSID: and signal:. -E is optional, but if you don't use it, think about escaping special meaning character. Here, it would be \(SSID\|signal\): The same regex can be used ...


0

You could use awk: echo $( iw dev wlp1s0 | awk '/(SSID|signal): /{$1 = ""; print;}' )


0

Maybe you should use a timeout instead of waiting indefinitely. The bash function below will block until the given search term appears or a given timeout is reached. The exit status will be 0 if the string is found within the timeout. wait_str() { local file="$1"; shift local search_term="$1"; shift local wait_time="${1:-5m}"; shift # 5 minutes as ...


0

I wanted to do something similar, redirecting mplayer output to lame, and I solved it with a FIFO. Try this: mkfifo fifo mplayer -ao pcm:file=fifo [option] [stream_url] & sox [option] fifo /tmp/out.wav rm fifo


1

pv behaves as cat if you pass files as arguments, and in this way you don't even need to pass -s. So you could just do: pv -w 20 $IN_FILE | grep ...


2

In your function definition, I would suggest replacing: echo "cat $1 | pv -w 20 -s ${__size}" with just: cat $1 | pv -w 20 -s ${__size} This way, the function itself will execute this bit of code, without requiring a call to eval in the caller.


1

You could write your own backend that runs the preprocessing and then hands it off to whatever actual backend you're normally using. When you set up the printer, you'd using your custom backend in the URI. I actually have done something similar to allow CUPS to print to a locally-patched LPRng server.


0

Presented solutions are too crazy for production use. From the fact that you seem fine with inotify approach (files are explicitly regenerated after master conf modification) it follows that you can just have a simple script which regenerates all your junk. There, inotify avoided with no loss of functionality. The upside is you have fewer things to debug ...


1

Totally different approach because I just know your eyes are rolling at that last answer. In this one, you're going to rely on inotify which means it's really Linux-specific. You're going to turn the problem on its head -- the individual configuration files will still be there, but you will re-generate them automagically each time there is a change to the ...


1

You have an application/program that reads all these .conf files and you want to consolidate them all into one file which dynamically spits out the appropriate information for the program's chosen file name. The problem with the pipe-based solution is that the program feeding the pipe cannot detect the file that the consumer has opened or wants to read. So ...


2

That has nothing to do with cat, pipes or buffering. Your "problem" is upstreams, at the terminal device. If every character you enter at the keyboard in the terminal was available for reading by your application immediately and cat, then would you enter aBackspacebReturn, your application would read a then ^? then b then ^M, which is not what you want and ...


-2

follow this loop: while((ch=getchar())!=EOF) { write(p[1],&ch,1); } with: char carriageReturn = 0x0D; write( p[1], &carriageReturn, 1 );


11

If stdout is not a tty (i.e. it's a regular file or a pipe) and if no --quiet option has been specified, apt-cache acts as if you had passed it --quiet=1. A workaround is to pass it a --quiet=0 option. $ apt-cache --quiet=0 policy foo 2>&1 | grep . N: Unable to locate package foo


3

A "better" solution would be to use a script utility: script -c "apt-cache policy foo" /dev/null | grep . That way it intercepts all the output and forwards it to the stdout. The only drawback is that you need to install the script if you don't have it yet. In ubunty it's provided by bsdutils package.


6

If you run strace apt-cache policy foo 2>&1 command, you can see the line ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 Because that command manipulates the 1(stdout), 1 is not written to stdout anymore. And if you redirect 2 to 1, you lost both of them. Edit: Here is a some code ...


10

There seems to be some cheaty behavior for redirections in apt-cache. But we can cheat a cheater by swapping stdout and stderr! Try this one, it should work: apt-cache policy foo 3>&1 1>&2 2>&3 3>&- | grep .


0

grep (i.e., /bin/grep) will read from standard input if it is invoked with no filename arguments.  So it is simple to write a script that runs grep with input from standard input — just invoke grep with no filename arguments.  But grep must be given (at least) one PATTERN argument (or equivalent).  An extremely inflexible way to do that, which is unlikely to ...


1

An alias will work. I have grep aliased to grep --color=auto: % which grep grep: aliased to grep --color=auto And piping to grep has the behavior you desire:


2

Chances are that the command's output is buffered. When the command writes to a terminal, the buffer is flushed on every newline, so you see it appear at the expected rate. When the command writes to a pipe, the buffer is only flushed when it reaches a few kilobytes, so it lags a lot. Thus is the default behavior of the standard input/output library. To ...


1

The perl way: command | perl -pe 's/(stuff)/\x1b[1m$1\x1b[0m/g' or with a continous output: A bash script for the output cont: #!/bin/bash while [ true ] do echo "Some stuff" done Test with: ./cont | perl -pe 's/(stuff)/\x1b[1m${1}\x1b[0m/g' \x1b[1m - bold or increased intensity ${1} - the backreferenze \x1b[0m - reset all attributes Output: ...


1

I would use awk command | awk '/some important stuff/ { printf "%c[31m%s%c[0m\n",27,$0,27 ; next } { print ; } ' where /some important stuff/ select important line, like in sed printf "%c[31m%s%c[0m\n",27,$0,27 ; print in red use 32,33 for green, yellow ... $1, $2, can be use to select a specific field other line are just printed 'as is' the ...


3

Answering your question literally, here's one way to list the last PID displayed by lsof: lsof … | awk 'END {print $2}' Awk is a text processing language which reads input and processes it line by line. In the code, END {…} executes the code in the braces after the whole input is processed, and effectively operates on the last line. $2 is the second ...


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


3

Many grep implementation will use line buffered when standard output is terminal. When standard output is terminal, it's often an interactive session, you want to get data as soon as possible. So grep will write data to standard output as soon as seeing a newline. When standard output isn't terminal (often meaning non-interactive session), grep will use ...



Top 50 recent answers are included