zsh-users
 help / color / mirror / code / Atom feed
* splitting and assigning
@ 2014-05-24  5:43 meino.cramer
  2014-05-24 14:27 ` Kurtis Rader
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: meino.cramer @ 2014-05-24  5:43 UTC (permalink / raw)
  To: zsh-users

Hi,

I have a looooooong list, whgich consists
of a 32 character long checksum (from md5sum),
two spaces and a absolute path with the checksummed file.

I want to split each line into two parts:
the checksum and the path/file and assign each part 
to a separate variable.

I tried to put this into a one-liner and failed using
${(s:  :)line}.

How can I do that?

Best regards and have a nice weekend!
Best regards,
mcc




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: splitting and assigning
  2014-05-24  5:43 splitting and assigning meino.cramer
@ 2014-05-24 14:27 ` Kurtis Rader
  2014-05-24 15:12 ` Eric Cook
  2014-05-25  3:20 ` S. Cowles
  2 siblings, 0 replies; 4+ messages in thread
From: Kurtis Rader @ 2014-05-24 14:27 UTC (permalink / raw)
  To: meino.cramer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1113 bytes --]

Use the right tool for the job. At some point you need to consider
switching to a different language. In Python the task is trivial. This is
from an iPython interactive session:

In [1]: data = ['md5sum#1  pathname#1', 'md5sum#2  pathname#2']

In [2]: data = [d.split() for d in data]

In [3]: data
Out[3]: [['md5sum#1', 'pathname#1'], ['md5sum#2', 'pathname#2']]

In [4]: checksums, pathnames = zip(*data)

In [5]: checksums
Out[5]: ('md5sum#1', 'md5sum#2')

In [6]: pathnames
Out[6]: ('pathname#1', 'pathname#2')




On Fri, May 23, 2014 at 10:43 PM, <meino.cramer@gmx.de> wrote:

> Hi,
>
> I have a looooooong list, whgich consists
> of a 32 character long checksum (from md5sum),
> two spaces and a absolute path with the checksummed file.
>
> I want to split each line into two parts:
> the checksum and the path/file and assign each part
> to a separate variable.
>
> I tried to put this into a one-liner and failed using
> ${(s:  :)line}.
>
> How can I do that?
>
> Best regards and have a nice weekend!
> Best regards,
> mcc
>
>
>
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: splitting and assigning
  2014-05-24  5:43 splitting and assigning meino.cramer
  2014-05-24 14:27 ` Kurtis Rader
@ 2014-05-24 15:12 ` Eric Cook
  2014-05-25  3:20 ` S. Cowles
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Cook @ 2014-05-24 15:12 UTC (permalink / raw)
  To: zsh-users

On 05/24/2014 01:43 AM, meino.cramer@gmx.de wrote:
> Hi,
>
> I have a looooooong list, whgich consists
> of a 32 character long checksum (from md5sum),
> two spaces and a absolute path with the checksummed file.
>
> I want to split each line into two parts:
> the checksum and the path/file and assign each part 
> to a separate variable.
>
> I tried to put this into a one-liner and failed using
> ${(s:  :)line}.
>
> How can I do that?
>
> Best regards and have a nice weekend!
> Best regards,
> mcc
>
>
>
while read -r sum file; do print -r - $sum $file; done < list


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: splitting and assigning
  2014-05-24  5:43 splitting and assigning meino.cramer
  2014-05-24 14:27 ` Kurtis Rader
  2014-05-24 15:12 ` Eric Cook
@ 2014-05-25  3:20 ` S. Cowles
  2 siblings, 0 replies; 4+ messages in thread
From: S. Cowles @ 2014-05-25  3:20 UTC (permalink / raw)
  To: meino.cramer; +Cc: zsh-users

On Sat, 24 May 2014, meino.cramer@gmx.de wrote:

> Date: Fri, 23 May 2014 22:43:23
> From: meino.cramer@gmx.de
>
> I want to split each line into two parts:
> the checksum and the path/file and assign each part
> to a separate variable.

another method:  if your data is in an array, cycle through the array.

ds=( ${(f)${"$(< your_data_file )"}} )
for l in ${ds} ; do e=( ${=l} ) ; echo "e1:  ${e[1]}, e2:  ${e[2]}" ; done


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-25  3:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-24  5:43 splitting and assigning meino.cramer
2014-05-24 14:27 ` Kurtis Rader
2014-05-24 15:12 ` Eric Cook
2014-05-25  3:20 ` S. Cowles

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).