| Post Reply | RetroFed Forum Forum Index » Linux |
| Author | Message | ||
|---|---|---|---|
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
I have a program that require all keywords to be in a single paragraph, most of the time, separated by commas For example: I have those terms 1-Term That i collected and organized into groups and subgroups with Titles and subtitles Title
But then i want to turn them into:
Removing certain marked words(Titles and sub-Titles), any Empty/Blank space, and Line breaks, while adding the commas between The Terms. I want to keep certain dashes "-"(like in words ) 1-Term,1.1 -Term,2-Term,3-Term,4-Term |
||
| 18 Original | |||
|
coreray00
discuss.online
coreray00@discuss.online Joined: 2024-01-13 |
|
||
| 3 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
Your description is too vague to really get a good answer. In general, if you're doing complex string manipulation, you'll use a full-fledged programming language with regex support, like Python, Perl or Awk, possibly piped into each other and/or other tools like Sed or Cut. I can't be more specific than that without a more specific description where you describe the actual data and criteria. Are you starting with the first or second example? Why do the prefix numbers change between examples? How do you tell text and title/subtitle apart? |
||
| 6 | |||
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
Your description is too vague to really get a good answer. In general, if you're doing complex string manipulation, you'll use a full-fledged programming language with regex support, like Python, Perl or Awk, possibly piped into each other and/or other tools like Sed or Cut. I can't be more specific than that without a more specific description where you describe the actual data and criteria. A...
Basically i collect keywords( e.g: transformers, A Deep dive, Harry Potter The worst, Xbox, stars worst, Jedi) from videos on my YouTube home page and organize them into a lists
And Turn it into:
Removing the titles and subtitles.
I was thinking of putting a symbol like "#" for example, in front of the Title
so the script knows to ignore that whole line, like in general programming |
||
| 1 | |||
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
Your description is too vague to really get a good answer. In general, if you're doing complex string manipulation, you'll use a full-fledged programming language with regex support, like Python, Perl or Awk, possibly piped into each other and/or other tools like Sed or Cut. I can't be more specific than that without a more specific description where you describe the actual data and criteria. A...
My bad, i fixed it I want to show that the two terms are related e,g Star and Jedi by grouping them together Franchises Stars wars Transformers Also i am not able to add line breaks between bullet points in markdown. so instead i get this Franchises
So i cant show the grouping thing in lemmy here. I would have also liked The list i make to be markdown compatible but i guess that separate issue. |
||
| 3 | |||
|
a14o
feddit.org
a14o@feddit.org Joined: 2025-01-15 |
Basically i collect keywords( e.g: transformers, A Deep dive, Harry Potter The worst, Xbox, stars worst, Jedi) from videos on my YouTube home page and organize them into a lists YouTuber terms: A Deep Dive The Worst Franchises: Star wars Jedi Harry Potter Transformers Companies: Xbox And Turn it into: A Deep Dive,The Worst, Star wars, Jedi, Harry Potter, Transformers,Xbox Removing the titles an...
This is not difficult to achieve at all with tools like |
||
| 4 | |||
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
This is not difficult to achieve at all with tools like sed or awk. But unless you provide a concrete example input file or files, all we can do is point to those tools.
Something like this?
Turned into
Both "Franchis" and "Cartoons" where removed/ not included with the other words. |
||
| 1 | |||
|
moonpiedumplings
programming.dev
moonpiedumplings@programming.dev Joined: 2023-08-10 |
Something like this? - Franchise(Title): - Harry potter - Perfect Blue - Jurassic world - Jurassic Park - Jedi - Star wars - The clone wars - MCU - Cartoons(Sub-Title): - Gumball - Flapjack - Steven Universe - Stars vs. the forces of Evil - Wordgril - Flapjack Turned into Harry potter,Perfect Blue,Jurassic world,Flapjack,Jedi,Star wars,The clone wars,MCU,Gumball,Flapjack,Steven Universe,Stars v...
This is technically yaml I think, a list (with one entry) of lists that contains mostly single items but also one other list. You should be able to parse this with a yaml parser like pythons built in one. Note that yaml is picky abiut the syntax though, so it wouldn't be able to handle deviations. |
||
| 1 | |||
|
non_burglar
lemmy.world
non_burglar@lemmy.world Joined: 2023-06-16 |
You can process these with bash string manipulation alone, but sed and awk will do this pretty easy. |
||
| 3 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
Something like this? - Franchise(Title): - Harry potter - Perfect Blue - Jurassic world - Jurassic Park - Jedi - Star wars - The clone wars - MCU - Cartoons(Sub-Title): - Gumball - Flapjack - Steven Universe - Stars vs. the forces of Evil - Wordgril - Flapjack Turned into Harry potter,Perfect Blue,Jurassic world,Flapjack,Jedi,Star wars,The clone wars,MCU,Gumball,Flapjack,Steven Universe,Stars v...
If you can stick to valid YAML like your example is, you can use a reasonably short
|
||
| 1 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
Something like this? - Franchise(Title): - Harry potter - Perfect Blue - Jurassic world - Jurassic Park - Jedi - Star wars - The clone wars - MCU - Cartoons(Sub-Title): - Gumball - Flapjack - Steven Universe - Stars vs. the forces of Evil - Wordgril - Flapjack Turned into Harry potter,Perfect Blue,Jurassic world,Flapjack,Jedi,Star wars,The clone wars,MCU,Gumball,Flapjack,Steven Universe,Stars v...
If you wanted a somewhat cruder approach using basically ubiquitous tools, you could do something like this:
Here I'm first using The above is hardly an efficient approach, but it does the job. |
||
| 3 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
If you wanted a somewhat cruder approach using basically ubiquitous tools, you could do something like this: $ grep '^ *-' /tmp/foo.txt | grep -v ': *$' | sed 's/ *- //' | tr '\n' ',' | sed s'/,$/\n/' Harry potter,Perfect Blue,Jurassic world,Jurassic Park,Jedi,Star wars,The clone wars,MCU,Gumball ,Flapjack,Steven Universe,Stars vs. the forces of Evil,Wordgril,Flapjack Here I'm first using grep ...
If you're feeling a little old school (and some might say masochistic), you could so a similar crude parser with a perl oneliner. This would be more efficient compute wise, but it's a bit of an acquired taste readability wise:
Here |
||
| 1 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
Something like this? - Franchise(Title): - Harry potter - Perfect Blue - Jurassic world - Jurassic Park - Jedi - Star wars - The clone wars - MCU - Cartoons(Sub-Title): - Gumball - Flapjack - Steven Universe - Stars vs. the forces of Evil - Wordgril - Flapjack Turned into Harry potter,Perfect Blue,Jurassic world,Flapjack,Jedi,Star wars,The clone wars,MCU,Gumball,Flapjack,Steven Universe,Stars v...
If you can't install a dedicated tool like
This takes the first argument on the command line, parses it as yaml, finds all leaf nodes recursively, and prints a comma-separated list of the results. |
||
| 2 | |||
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
If you wanted a somewhat cruder approach using basically ubiquitous tools, you could do something like this: $ grep '^ *-' /tmp/foo.txt | grep -v ': *$' | sed 's/ *- //' | tr '\n' ',' | sed s'/,$/\n/' Harry potter,Perfect Blue,Jurassic world,Jurassic Park,Jedi,Star wars,The clone wars,MCU,Gumball ,Flapjack,Steven Universe,Stars vs. the forces of Evil,Wordgril,Flapjack Here I'm first using grep ...
I think this is The solutions that makes the most sense to me But i don't understand what
Why do we replace the commas again with new lines? Also, I figure a better way to group related terms
Using semicolons ";"
But do i just pipe
Into
Or is there a way to combine them. I don't see an option to do more than operation in Lastly, i have been trying to use regex to match
To
I just need to match The "X" There, the program takes care of the rest I tried
On this website to match
But using the debugger, it only recgnize "The" and then stops |
||
| 1 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
I think this is The solutions that makes the most sense to me But i don't understand what sed does here replace the trailing comma with a newline again Why do we replace the commas again with new lines? Also, I figure a better way to group related terms Stars Wars;Clone Wars;Jedi Using semicolons ";" I figure i can replace them with commas using tr command tr ';' ',' But do i just pipe tr '\n' ...
Consider this two-line output:
We convert the newlines to commas. Now there is a comma at the end of the last line as well, and because of no newline, the next prompt is at the end of the output:
Substituting only the last comma (
These two commands have equivalent output:
What tr does is take a list of characters in parameter 1 and converts them to the equivalent position character in parameter 2. There's a little more to it (it supports ranges, for example), but this will do the job. To learn more you can run
The other problem with regex is that every implementation does things differently. For example, sed would interpret that plus as a literal |
||
| 1 | |||
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
Why do we replace the commas again with new lines? Consider this two-line output: $ echo 'a\nb' a b $ We convert the newlines to commas. Now there is a comma at the end of the last line as well, and because of no newline, the next prompt is at the end of the output: $ echo 'a\nb' | tr '\n' , a,b,$ Substituting only the last comma ($ means end of line) allows us to get the output we expected: $ ...
That because the program/ add-on i am using, only requires certain keywords to blacklist videos so if it find
Th developer links to Firefox's developers Regex Documentation.
This is a snip-it of the the add-on Guide. I cant like to it cuz for some reason its only inside the extension but here is the add-on's page |
||
| 1 | |||
|
bus_factor
lemmy.world
bus_factor@lemmy.world Joined: 2023-10-01 |
second part you’re not matching at all. That because the program/ add-on i am using, only requires certain keywords to blacklist videos so if it find What "X" Says About in a Video Title , it doesn't need the rest of the sentence to blacklist the video. The other problem with regex is that every implementation does things differently Th developer links to Firefox's developers Regex Documentatio...
We're talking about different halves. The regex |
||
| 1 | |||
Cactus_Head
programming.dev
cactus_head@programming.devJoined: 2023-11-25 |
We're talking about different halves. The regex \w+\s+ matches "The " ("The" followed by a space), not "The MCU".
Ah, sorry i thought you meant after "About". |
||
| 1 | |||
| Post Reply |
Back to top |