![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk and sed filtering | invinzin21 | Shell Programming and Scripting | 2 | 01-11-2008 03:56 AM |
| port filtering | ujjwalmohan | HP-UX | 0 | 11-26-2007 01:18 AM |
| awk filtering ? | varungupta | UNIX for Advanced & Expert Users | 4 | 09-17-2007 03:55 AM |
| process filtering | pradeepmacha | Shell Programming and Scripting | 6 | 04-11-2005 11:18 AM |
| gcc version filtering !! | amol | Shell Programming and Scripting | 4 | 06-28-2002 02:30 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Pipe filtering
Hi, The thing is that sometimes I need to filter an arbitrary output given a condition (think on the "filter" function present on some programming languages) from the shell (I use sh/bash). I tried this: Code:
#!/bin/sh
# Usage: filter command [options_for_xargs]
COMMAND=$1
shift 1
xargs "$@" -I "{}" sh -c "if $COMMAND; then echo {}; fi"
And now, if I want to get all the non-executable files under /etc, I can run this: Code:
$ find /etc -type f -print0 | filter "! test -x {}" -0
/etc/fam.conf
/etc/cups/cupsd.conf
/etc/cups/snmp.conf
/etc/cups/lpoptions
/etc/cups/mime.types
....
So the question is... is there any better/faster way of doing this generic filter with sh/bash? thanks! |
|
||||
|
FWIW: find supports the -mode option - you use this to test permissions bits.
Your generic filter invokes a whole new process, which may not be all that efficient when compared to other options available to a command. It is an interesting idea, though. Have you considered the concept of a coprocess using named pipes? See the bash FAQ here: ftp://ftp.cwru.edu/pub/bash/FAQ |
|
||||
|
Quote:
Quote:
Code:
#!/bin/sh
COMMAND=$1
while read LINE; do
eval "${COMMAND/\{\}/$LINE}" && echo $LINE
done
Quote:
Code:
xargs "$@" -I "{}" echo "$COMMAND && echo {}" | sh
It's not as fast as the pure bash solution, but is cheaper to run "echo"s than "sh"s processes. If it was possible to for xargs to output the command without actually running it, it should really fast (there is no such option AFAIK) thanks |
![]() |
| Bookmarks |
| Tags |
| filter shell xargs |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|