[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using mapfile is extreamly slow compared to oldfashinod ways to read
From: |
Stephane CHAZELAS |
Subject: |
Re: using mapfile is extreamly slow compared to oldfashinod ways to read files |
Date: |
Fri, 27 Mar 2009 11:21:51 +0000 (UTC) |
User-agent: |
slrn/pre1.0.0-2 (Linux) |
2009-03-26, 21:22(-04), Chet Ramey:
> Chris F.A. Johnson wrote:
>
>> Chet, how about an option to mapfile that strips leading and/or
>> trailing spaces?
>>
>> Another useful option would be to remove newlines.
>
> I'm disinclined to add one, since it's easy enough to use the
> ${line##[ ]} and ${line%%[ ]} constructs to remove
> leading and trailing whitespace. You can use the same expansions
> or pattern substitution to remove newlines (using $'\n' to denote
> a newline).
[...]
That removes only one blank, to strip all blanks, you'd need to
enable ksh extended globbing (shopt -s extglob) and do
${line##+([[:blank:]])}
Or POSIXly:
${line#"${line%%[![:blank:]]*}"}
Not extremely legible.
Note that "read" does strip leading and trailing blanks (as long
as those blank characters are in IFS and as long as a variable
name is provided to it), so it's not completely unreasonable to
ask that "readarray" (aka mapfile) has an option to do that as
well.
--
Stéphane
- using mapfile is extreamly slow compared to oldfashinod ways to read files, Lennart Schultz, 2009/03/26
- Re: using mapfile is extreamly slow compared to oldfashinod ways to read files, Greg Wooledge, 2009/03/26
- Re: using mapfile is extreamly slow compared to oldfashinod ways to read files, Chet Ramey, 2009/03/26
- Re: using mapfile is extreamly slow compared to oldfashinod ways to read files, Chris F.A. Johnson, 2009/03/26
- Re: using mapfile is extreamly slow compared to oldfashinod ways to read files, Greg Wooledge, 2009/03/27
- Re: using mapfile is extreamly slow compared to oldfashinod ways to read files, Lennart Schultz, 2009/03/27