Re: commands to manipulate files



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.

.



Relevant Pages

  • Re: Can you improve on this command line?
    ... > You seem to have a mania for efficiency? ... stand for Fandarel), I'd be writing in C, not shell. ... script entered at the command prompt, ...
    (comp.os.linux.misc)
  • Re: #! variable in shebang
    ... because the kernel can start the ... >interpreter immediately, rather than starting a shell, which has to do ... That "efficiency things" are, in this day and age, ... as much vanity as the next person ...
    (comp.unix.shell)
  • Re: File Name Completion
    ... >>The default shell is tcsh. ... > (on a just booted iMac). ... Gives perspective on OS efficiency. ...
    (comp.unix.solaris)
  • Re: Running an application for N days??
    ... > How often does find run in that script? ... A shell is a tool to run ... you're concerned about efficiency, you should not use shells at ... or the perl equivalent, ...
    (comp.unix.shell)