Hacker News new | past | comments | ask | show | jobs | submit login

Not declarative, but Perl can do something like that.

Delimeters/Regex:

  $ perl -ne '($name,$pass,$uid,$gid,$therest)=split(/:/);print "$name $gid\n"' /etc/passwd
  root 0
  daemon 1
  bin 2
  ...
Fixed width:

  $ printf "1234XY\n5678AB" | perl -ne '($f1,$f2)=unpack("a4 a2");print "$f2 $f1\n"'
  XY 1234
  AB 5678
I believe Rexx's parse is fancier still, but this is reasonably close.



You might want to look into what the following cli options do for you:

perl -F':' -anE 'say $F[0]'


That is indeed good. I used a bit of Perl a few years back but it has slipped out of my mind.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: