in reply to Re: one liner to capture value of field and insert in another field
in thread one liner to capture value of field and insert in another field

I guess i jumped the gun a little bit. My apologies. It works for the sample i provided, but the real file has almost 300 fields in each record..some of those values are populated and some aren't...so simply joining a "|" at the end doesn't work for the actual file.

is there a way to do what you did but instead of Joining one pipe at the end can we somehow join the remaining ~300 col values to each record?

row|1|CUSIP|35472T200|ARDIV|||20150112|||||||||||||||||||||||||||||||| +|||||||||||||||||||||20150321||||||G||||||||||||||||||||FR||||||||||| +||||||||||||||||||||||||||||||||||||X|||||||||||||||||||||||||||||||| +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +||||||||||||||||||||||||||||||||||||||||LIQ|||||||||||||||||||||||||| +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +||||||||||||

Sorry for the incomplete data and thx again.

  • Comment on Re^2: one liner to capture value of field and insert in another field
  • Download Code

Replies are listed 'Best First'.
Re^3: one liner to capture value of field and insert in another field
by choroba (Cardinal) on Jan 28, 2015 at 16:38 UTC
    The problem with split is that by default, trailing empty fields are discarded. You can specify a negative count to prevent that, but you need to be more explicit in such a case:
    perl -lne '@F = split /\|/, $_, -1; $F[10] = $F[7] ; print join "|", +@F'
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I was just about to say that! :) It took me a while to figure out what dirtdog is saying about his file.
Re^3: one liner to capture value of field and insert in another field
by Anonymous Monk on Jan 28, 2015 at 16:09 UTC
    You mean the records are spread out across several lines? And what separates them?

      it's a pipe delimited file with around 300 columns. So i just need to take the date that would be in column 8 and insert it into column 11, but all other values stay the same.