Can someone help with a regular expression?

by 4 replies
5
Hello,

If you don't mind a free tip for a newbie, I have a list of 70 words, and I need to repeat each 10 times to add up 700 times 70 sets of words repeated 10 times each.

Can you save me the copy-paste nightmare with a regular expression? I have Linux or Notetab Light in Windows. The first one allows for, the second one allows regexes in Perl.

Thanks!
#programming #expression #regular
  • You use RegEx mainly to find something and then maybe replace it with something else, not just to copy and paste something.

    How is pasting something 10 times a nightmare?

    An example of what you want to do would be really helpful.
  • I want to turn this...

    a
    b


    ...into...

    a
    a
    a
    a
    a
    a
    a
    a
    a
    b
    b
    b
    b
    b
    b
    b
    b
    b
    b


    ...You get it. I want to replace a for a,a,a,a,a,a,a,a,a,a,a in short. Can it be done?
  • Yes, assuming that you have access to a bash shell (i.e. do you have shell access on your server?)
    Put each line (in your example it was a,b...) into a file (in my case I used foo.txt)
    Then run this double for-loop...

    for line in `cat foo.txt`; do for i in {0..9}; do echo $line; done; done
    • [ 1 ] Thanks
  • Thank you.

Next Topics on Trending Feed