Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: repeat data at one line and grep as pre-set format

by Random_Walk (Prior)
on Jan 24, 2006 at 15:15 UTC ( #525196=note: print w/replies, xml ) Need Help??


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

I think you want to split each pair of data points out to a line on its own instead of having multiple datapoints on one line.

cat yourfile.txt | perl -ple 's/(\S+\s+\S+)\s+/$1\n/g'

should do this for you as long as you have even numbers of datapoints on each line

echo "00000001 99888 00000011 99889 00000002 99890 00000003 998 +08" \ | perl -ple 's/(\S+\s+\S+)\s+/$1\n/g' 00000001 99888 00000011 99889 00000002 99890 00000003 99808

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: repeat data at one line and grep as pre-set format
by davido (Archbishop) on Jan 24, 2006 at 18:32 UTC
    cat yourfile.txt | perl -ple 's/(\S+\s+\S+)\s+/$1\n/g'

    Isn't that the same as:

    perl -ple 's/(\S+\s+\S+)\s+/$1\n/g' yourfile.txt

    UUOC.


    Dave

      You are right and your way is more efficient too. I wrote it with the cat file | as that is how I tested it with echo, just failed to engage my brain completely :-)

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://525196]
help
Chatterbox?
shmem puts down the Canon garments and dresses as Chancellor
[vrk]: Congratulations. You should have Cookies
[shmem]: thanks vrk - but I'll rather have a plate of "silly con charme"
Lady_Aleena is trying to explain perl regexen to people right now and explaining how variables expand in regexen.
[Lady_Aleena]: The people I'm talking with think /$var/ looks weird with some saying it shouldn't work.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-04-28 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (520 votes). Check out past polls.