>>> sed $'s/[^[:print:]\t]//g' /home/shay/rawdata.txt > /home/shay/output.txt
I'm curious why you have the `$` before the script? It doesn't seem
to matter on my system whether it's there or not, but I'm just curious
why it's there.
>> When you call sed in your script make sure you're calling sed with it's full path.
>>
>> cron has a more restricted shell so what may be in your users $PATH may not be seen from cron
I agree with George, it may be that you have multiple `sed`s on the
first system, and cron's `$PATH` is probably preferring `/bin/sed`,
which may be an older, or at least non-GNU, `sed` that is interpreting
your "character class" `[;print:]` as those individual characters (or
may be stopping the "bracket expression" at the `]`). And the `$PATH`
in your interactive `bash` prefers a different `sed`, say,
`/usr/bin/sed`, which understands "character classes". When you use
the full path, like George said, you know which `sed` you're using,
because it's not determined by the order of `$PATH`.
And what Bob said made me wonder if using GNU `sed`'s
`--regexp-extended` (or `-E`) for "extended regular expression"
support may help? This breaks the POSIX portability that Bob
recommended, however, but is closer to your original command.
Bob also makes a great suggestion that perhaps using `perl` instead
would be better (don't have to worry about POSIX/older/non-GNU
versions). But that also made me go in the opposite direction to a
simpler filter: `tr`. This does what you want with the exception that
it also joins the lines (which I assume is not desired):
tr --complement --delete '[:print:]\t' <shayrawdata.txt
...and follows the mantra "Don't use `awk` when `sed` will do. Don't
use `sed` when `tr` will do." ... etc
I personally love regular expressions (I don't use "character classes"
that much), but the problem is that there are 4 different types. And
the program you're using depends on which one is preferred. When you
use PCRE (Perl-Compatible Regular Expressions) in languages like Perl,
Python, and Javascript you don't have to guess which one it is, it's
PCRE. But different versions of `tr`, `sed`, `awk`, `vi`, etc may
have had PCRE added on much later, so one of the other 4 REs is
preferred.
--Jas
.
..:
> To view this discussion on the web visit
https://groups.google.com/d/msgid/uclug/CADuw60tzs1LQLoTY9YMLuaB05yKTDNd-8QVtXpdg19VYO3JqRA%40mail.gmail.com.