You're replying to a comment by Peter Krumins.

March 26, 2013, 16:45

Hi Stuart!

It's definitely possible to do that. Here's the basic idea. First you'd split the line into left and right, and then split the right part into fields:

perl -nle "
 my ($left, $right) = split '=', $_, 2;
 my @fields = split '~', $right;
"

Now you just have to test if $left is something that you're looking for, for example, if it is "ADVJSMF":

perl -nle "
 my ($left, $right) = split '=', $_, 2;
 my @fields = split '~', $right;
 if ($left eq 'ADVJSMF') {
   # do something
 }
"

Now just replace # do something with the actual thing to do. For example, to print First Name, you'd print $fields[2]:

perl -nle "
 my ($left, $right) = split '=', $_, 2;
 my @fields = split '~', $right;
 if ($left eq 'ADVJSMF') {
   print $fields[2];
 }
"

Modifying fields is a bit trickier as it involves re-assembling the fields, left part and right part.

But here's how you'd do it:

perl -nle "
 my ($left, $right) = split '=', $_, 2;
 my @fields = split '~', $right;
 if ($left eq 'ADVJSMF') {
   $fields[2] = 'New First Name';
 }
 my $new_fields = join '~', @fields;
 print $left, '=', $new_fields;
"

This modifies the First Name, and then prints the updated line.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "cloud_303": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.