Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Read file with escaped newlines into array
- X-seq: zsh-users 20967
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Read file with escaped newlines into array
- Date: Thu, 19 Nov 2015 11:17:49 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=chchu1a8Fw0yZ7lGA0hh9FOxphuyWjx25F5wQkYhFeY=; b=U03b6hiupkPAy8rcq8L0ttFLSk+bjbFqi2h25Q1myXTlib0iQTm/HiHkEdR5BAWh1h u4ERFNWL8BXVjqhkh6zTiZBEm+EapX+D9fMr2OqKq8KDNgh0HYRFZHK8eHgrVonX3tEr 912UP8Bi9skZwb5e+bvisiy7cEtDVuEvZytlriJ/F2G86uAfGn3eko2zQFK8yICLESLm D+VCjCuA5sVr6k2AMMFTNhHr3DL7dFQzMTkbKb/lxXI6jymjKj5yfiTlJF5BiqUyNU7d cp9DCZv4a2OI3AkK/iJ7K1ZPLGWX4k29oJxUAZFQGfpGypktyWT+f7NNvsN/FfHNULo7 zHog==
- In-reply-to: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCZzEfKkcWyPUb58ffmne6E8Eh6_CDpeLc0efd6hEQAow@mail.gmail.com>
On Nov 19, 6:34pm, Sebastian Gniazdowski wrote:
}
} fc -W stores history to a given file. It escapes newlines with \. How
} to read such file into array and have "\^M" lines put back together
} into single array entries?
The best way is probably to use the history mechanism to read it:
() { fc -ap -R the_given_file ; the_desired_array=( ${history} ) }
Although the docs don't yet say so, the special associative array
$history is not implemented as a hash table, so the entries are
guaranteed to be in a fixed order from most recent (largest history
number) to longest ago. Which is the reverse of the way you'd read
them from the file, so you might want ${(Oa)the_desired_array} when
referencing.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author