Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/02/05
- Next message: Ed Morton: "Re: need help on shell scripting"
- Previous message: Michael Tosch: "Re: need help on shell scripting"
- Next in thread: Markus Gyger: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Reply: Markus Gyger: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Reply: Heiner Steven: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Maybe reply: Stephane CHAZELAS: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 02 May 2005 08:43:49 -0500
Heiner Steven wrote:
> SHELLdorado Newsletter 1/2005 - April 30th, 2005
Are you asking us to review these suggestions or are they part of a FAQ
(or some other list) that's previously been reviewed or something else?
Assuming the former:
<snip>
> -----------------------------------------------------------------
> >> Shell Tip: How to read a file line-by-line
> -----------------------------------------------------------------
<snip>
> file=/etc/motd
> OIFS=$IFS; IFS= # Change input field separator
> while read -r line
> do
> echo "$line"
> done < "$file"
> IFS=$OIFS # Restore old value
Or, preferably:
file=/etc/motd
while IFS= read -r line
do
echo "$line"
done < "$file"
<snip>
> -----------------------------------------------------------------
> >> Shell Tip: Print a line from a file given its line number
> -----------------------------------------------------------------
<snip>
> lineno=5
> sed -n "${lineno}{p;q;}"
>
> So you think you have a better solution for this problem?
> Prove it: send me your suggestion
> (heiner.steven@shelldorado.com, closing date: 2005-05-31),
> and I'll measure the speed of all contributions on a Linux
> and a Solaris system. The fastest (or most elegant) solution
> using only POSIX shell commands will be published in the
> next SHELLdorado Newsletter.
We saw in a different thread recently (http://tinyurl.com/87c8d) about a
similair problem that both of these might be faster than the sed
approach in this case:
head -n "${lineno}" | tail -1
awk -vln="${lineno}" 'NR==ln{print;exit}'
>
> -----------------------------------------------------------------
> >> Shell Tip: How to convert upper-case file names to lower-case
> -----------------------------------------------------------------
<snip>
> Admit it: you sometimes copy files from an operating system
> with a name ending in *indows. A frequent annoyance are file
> names IN ALL UPPER CASE.
>
> The following command renames them to contain only lower
> case characters:
>
> for file in *
> do
> lcase=`echo "$file" | tr '[A-Z]' '[a-z]'`
This doesn't seem worth mentioning as I'd imagine it's the first thing a
newbie would do anyway.
<snip>
> -----------------------------------------------------------------
> >> Shell Tip: How to avoid "Argument list too long" errors
> -----------------------------------------------------------------
<snip>
> Examples:
>
> o Don't specify arguments, to get the (hopefully) useful
> default:
>
> $ ls
>
> o Use shell-internal functionality ("echo" and "for" are
> shell-internal commands):
>
> $ echo *
> file1 file2 [...]
>
> $ for file in *; do rm "$file"; done # be careful!
>
> o Use "xargs"
>
> $ ls | xargs rm # careful!
>
> $ find . -type f -size +100000 -print | xargs ...
>
> o Limit the number of arguments for a command:
>
> $ ls [a-l]*
> $ ls [m-z]*
>
> Using this techniques should help getting around the
> problem.
Again, none of these except the "xargs" one, seem worth mentioning as
they're all obvious even to a newcomer.
Ed.
- Next message: Ed Morton: "Re: need help on shell scripting"
- Previous message: Michael Tosch: "Re: need help on shell scripting"
- Next in thread: Markus Gyger: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Reply: Markus Gyger: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Reply: Heiner Steven: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Maybe reply: Stephane CHAZELAS: "Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|