Adding a character and a number (as part of a sequence) at the end of each line
-
Hello All,
I have a long list of words:
apple
apricot
avocado
banana
blackberry
blackcurrant
.
.
.and I’d like to achieve the following format:
apple/1
apple/2
apple/3
apple/4
apple/5
apple/6
apricot/1
apricot/2
apricot/3
apricot/4
apricot/5
apricot/6
avocado/1
avocado/2
avocado/3
avocado/4
avocado/5
avocado/6
banana/1
banana/2
banana/3
banana/4
banana/5
banana/6
blackberry/1
blackberry/2
blackberry/3
blackberry/4
blackberry/5
blackberry/6
blackcurrant/1
blackcurrant/2
blackcurrant/3
blackcurrant/4
blackcurrant/5
blackcurrant/6
.
.
.Every fruit needs exactly six instances.
What way can I achieve this?Thank you and have a nice day,
Viktoria -
in your given example you can do this by doing a search/replace using regular expressions
open the search replace window and select regular expression in the lower left cornerthen use following search/replace strings:
find what:^(.*?)$
replace with:$1/1\r\n$1/2\r\n$1/3\r\n$1/4\r\n$1/5\r\n$1/6and hit replace all
so if your text was:
apple
apricot
avocado
banana
blackberry
blackcurrantyou will get:
apple/1
apple/2
apple/3
apple/4
apple/5
apple/6
apricot/1
apricot/2
apricot/3
apricot/4
apricot/5
apricot/6
avocado/1
avocado/2
avocado/3
avocado/4
avocado/5
avocado/6
banana/1
banana/2
banana/3
banana/4
banana/5
banana/6
blackberry/1
blackberry/2
blackberry/3
blackberry/4
blackberry/5
blackberry/6
blackcurrant/1
blackcurrant/2
blackcurrant/3
blackcurrant/4
blackcurrant/5
blackcurrant/6 -
Dear @Meta Chuh,
Thank you so much for your help, this is exactly what I wanted.
Just theoretically, if the number of instances would be much higher and every fruit needs for example 100 lines, so the final text displayed as:
apple/1
apple/2
apple/3
.
.
.
apple/100
apricot/1
apricot/2
apricot/3
.
.
.
apricot/100
.
.
.is there any shorter formula that can do that so no need to type your expression individually to
<...$1/99\r\n$1/100>I tried to edit your replace field you provided but I’m not at this level of understanding and had no success.
Thank you,
Victoria -
Hello, @viktoria-ontapado, and All,
Here is my solution, for any number of repetitions !
Assuming, for instance, your initial block of text, with the
6lines, as below :apple apricot avocado banana blackberry blackcurrant-
First, paste this block in a new tab, with a line break after the sixth line ( IMPORTANT )
-
Display the Line Numbers column with the menu option Settings > Preferences… > Editing > Display line number
Now, if you want to get, let’s say, 50 values of each fruit , that means that your total text will contain
6x50=300lines-
So, select the entire block (
Ctrl + A) -
Hold down the
Ctrl + Dshortcut, while having a look, in the bottom status bar, at the partlines: xxx -
And release the keys, as soon as you get the number
301 -
Now, move back at beginning, if necessary (
Ctrl + Home) -
Open the column editor (
Alt + C)-
Choose the Number to Insert feature
-
Fill in the number
1in the Initial number and Increase by boxes -
Type in the number
6in the Repeat zone ( your number of fruits ) -
Check the Leading zeros box ( IMPORTANT )
-
Select, if necessary, the dec format
-
Click on the OK button
-
-
Open the Replace dialog (
Ctrl + H)-
In the Find what: box, fill in the regex
(?-s)(\d+)(.+) -
In the Replace with: box, fill in the regex
\2/\1 -
Check the Wrap around and Regular expression options
-
Click on the Replace All button
-
=> In each line, the numbers and the fruit’s names are swapped, separated by the
/symbol !- Finally, perform a classic alphabetic sort, using the option Edit > Line Operations > Sort Lines Lexicographically Ascending
Et voilà !
Optionally, you may get rid of the leading zeros, in numbers, with the simple regex S/R :
SEARCH
/0+REPLACE
/Best Regards,
guy038
-
-
Hello @guy038,
I was hoping you could check this topic.
Thank you very much for your creative solution, I really appreciate it.
I’ve already tested it with my other lists and it’s working like a charm.Have a nice week,
Viktória
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login