in reply to Re: repeat data at one line and grep as pre-set format
in thread repeat data at one line and grep as pre-set format

Imo if you are going to do that then you should just do an s///

perl -pe "s/(\d{8}\s+\d{5})(\s+)/$1\n/g" t.txt

In sure there is a way to do that without needing to copy $1, but I couldnt work it out quickly enough to post.

---
$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^3: repeat data at one line and grep as pre-set format
by davido (Cardinal) on Jan 24, 2006 at 10:13 UTC

    You could avoid copying $1 if you use lookbehind, but there is that pesky problem of \s+ between the digit fields, which won't work with lookbehind (variable width rule). I couldn't tell by the OP's post whether there was a fixed number of spaces or not. Assuming only two spaces (or at least a known quantity of spaces) between the column fields, you could do something like this:

    perl -pe "s/(?<=\d{8}\s\s\d{5})\s+/\n/g;" t.txt

    Dave

      You could use a combination of lookbehind and lookahead:

      perl -pe "s[(?<=\d{5})\s+(?=\d{8})][\n]g" t.txt

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.