Re: commands to manipulate files
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Tue, 29 Apr 2008 07:59:29 -0500
On 4/29/2008 7:35 AM, mop2 wrote:
Ed Morton wrote:
On 4/29/2008 6:45 AM, mop2 wrote:
Thanks CHAZELAS!
Very good explanation.
I like read his posts, excelent for learning about most unixes
peculiarities.
My focus will never be portability and my environments are always
under my control.
My universe is very limited and pure shell is always my start point.
Serious question - to me, the shell is an environment from which to call
appropriate tools in a specific order to get a job done, so what does "pure
shell" mean to you?
I don't see problems with escaped "*" in standard input in that case,
for bash at lest.
For small files I think the shell will be more efficient than the use
of a call to an external tool that isn't in the cache.
Whether that's true or not, for small files efficiency doesn't matter so is
there any other reason to prefer:
Y=;while read -d\* ;do [ $Y ]&&echo "$REPLY"&&Y=||Y=1;done < file
over:
awk -v RS='*' '!(NR%2)' file
Regards,
Ed.
Hi Ed:
Q1
For me "pure shell" is the use of the shell exclusively, without
external programs.
So, if you need to find out how many characters are in a file, you'd do
something other than "wc -c"? I don't mean to preach, it's just that I find
trying to avoid external commands less easy to understand than trying to avoid
cars in favor of horse-and-cart. Perhaps it's a new paradigm - Amish Programming
;-).
Q2
Using the small file posted as exampe:
Shell bash:
$ time { Y=;while read -d\* ;do [ $Y ]&&echo "$REPLY"&&Y=||Y=1;done <
file;}
real 0m0.001s
user 0m0.004s
sys 0m0.000s
I don't use awk for myself.
The first call:
$ time awk -v RS='*' '!(NR%2)' file
real 0m0.051s
user 0m0.000s
sys 0m0.000s
The next:
$ time awk -v RS='*' '!(NR%2)' file
real 0m0.006s
user 0m0.000s
sys 0m0.004s
My point was that efficiency isn't a concern for small files since, as you show
above, the script runs in the blink of an eye either way, I was just wondering
if there was any reason other than efficiency to avoid external commands.
I see the things in this way.
The relevance of all this is a question of view point and is very
personal.
OK, thanks for explaining. Obviously, you don't have to justify your view point
to me - I was just curious...
Ed.
.
- References:
- commands to manipulate files
- From: Nezhate
- Re: commands to manipulate files
- From: Nezhate
- Re: commands to manipulate files
- From: Stephane CHAZELAS
- Re: commands to manipulate files
- From: Nezhate
- Re: commands to manipulate files
- From: Ed Morton
- commands to manipulate files
- Prev by Date: Re: commands to manipulate files
- Next by Date: Re: commands to manipulate files
- Previous by thread: Re: commands to manipulate files
- Next by thread: Re: commands to manipulate files
- Index(es):
Relevant Pages
|
|