You are not logged in.

#1 2021-09-06 17:58:01

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

[SOLVED] simple bash script that opens all url in .txt file?

Hi there,

I cant find a bash script that would allow me to open all links (one per line in .txt) at once.

Is there even one in the wild or has someone even the skills to publish one in this topic? It would came in handy.

In hope of supportive answers.

Last edited by ArchNewbieKernel (2021-09-07 14:46:18)

Offline

#2 2021-09-06 18:00:40

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] simple bash script that opens all url in .txt file?

Just read each line into something like xdg-open?

What have you come up with so far?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2021-09-06 18:52:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] simple bash script that opens all url in .txt file?

while read url; do $BROWSER "$url"; done < url_list.txt

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2021-09-06 19:01:17

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [SOLVED] simple bash script that opens all url in .txt file?

$BROWSER $(<url_list.txt)

Does not work with xdg-open.

Offline

#5 2021-09-07 09:07:10

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

Re: [SOLVED] simple bash script that opens all url in .txt file?

Trilby wrote:
while read url; do $BROWSER "$url"; done < url_list.txt
#!/bin/bash

while read url; do $LibreWolf "$url"; done < YT-SUBSCRIPTIONS.txt

is outputting

./ytsubsopen.sh
./ytsubsopen.sh: line 3: $'bald and bankrupt\r': command not found
: No such file or directorytps://www.youtube.com/channel/UCxDZs_ltFFvn0FDHT6kmoXA
./ytsubsopen.sh: line 3: $'Simple History\r': command not found
: No such file or directorytps://www.youtube.com/channel/UC510QYlOlKNyhy_zdQxnGYw
./ytsubsopen.sh: line 3: $'Reactistan\r': command not found
: No such file or directorytps://www.youtube.com/channel/UCWGmhDFi3fB5DA1nuVRsPIQ

.

seems like the one-liner removes 'ht' in URL in each line.

my YT-SUBSCRIPTIONS.txt looks like this

# bald and bankrupt
https://www.youtube.com/channel/UCxDZs_ltFFvn0FDHT6kmoXA
# Simple History
https://www.youtube.com/channel/UC510QYlOlKNyhy_zdQxnGYw
# Reactistan
https://www.youtube.com/channel/UCWGmhDFi3fB5DA1nuVRsPIQ

Offline

#6 2021-09-07 09:16:51

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [SOLVED] simple bash script that opens all url in .txt file?

sed '/^#/d' YT-SUBSCRIPTIONS.txt | xargs $LibreWolf

Offline

#7 2021-09-07 09:22:22

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

Re: [SOLVED] simple bash script that opens all url in .txt file?

lambdarch wrote:
sed '/^#/d' YT-SUBSCRIPTIONS.txt | xargs $LibreWolf

this outputs a single URL in terminal only which I can click on.

Offline

#8 2021-09-07 09:30:05

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [SOLVED] simple bash script that opens all url in .txt file?

Oh this is a mac file, or windows?
To be sure:

sed -z 's/\r/\n/g' YT-SUBSCRIPTIONS.txt | sed -E '/^#|^$/d' | xargs $LibreWolf

Last edited by lambdarch (2021-09-07 09:31:10)

Offline

#9 2021-09-07 09:35:16

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

Re: [SOLVED] simple bash script that opens all url in .txt file?

lambdarch wrote:

Oh this is a mac file, or windows?
To be sure:

sed -z 's/\r/\n/g' YT-SUBSCRIPTIONS.txt | sed -E '/^#|^$/d' | xargs $LibreWolf

??? This is a ARCH LINUX Forum.

It now displays all links in terminal instead of opening them in browser directly.

Last edited by ArchNewbieKernel (2021-09-07 09:36:40)

Offline

#10 2021-09-07 09:44:42

lambdarch
Member
Registered: 2021-01-10
Posts: 67

Re: [SOLVED] simple bash script that opens all url in .txt file?

Well, you seem to have some "\r" in your file:

ArchNewbieKernel wrote:

./ytsubsopen.sh: line 3: $'bald and bankrupt\r': command not found

If $LibreWolf is a web browser the above command should work, it's up to you now...

Offline

#11 2021-09-07 09:47:38

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

Re: [SOLVED] simple bash script that opens all url in .txt file?

lambdarch wrote:

Well, you seem to have some "\r" in your file:

ArchNewbieKernel wrote:

./ytsubsopen.sh: line 3: $'bald and bankrupt\r': command not found

If $LibreWolf is a web browser the above command should work, it's up to you now...

this is wrong because there is no "\r", is just the empty void after the link in the same line.

Last edited by ArchNewbieKernel (2021-09-07 09:50:08)

Offline

#12 2021-09-07 10:05:57

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] simple bash script that opens all url in .txt file?

Why have you replaced $BROWSER with $LibreWolf?
You were meant to either use it as-is if you have the correct environmental variable set or replace it with the name of the browser binary (excluding the $).


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#13 2021-09-07 10:47:38

seth
Member
Registered: 2012-09-03
Posts: 49,951

Re: [SOLVED] simple bash script that opens all url in .txt file?

ArchNewbieKernel wrote:

this is wrong because there is no "\r", is just the empty void after the link in the same line.

Don't argue with facts. You lose.
https://en.wikipedia.org/wiki/Newline

Offline

#14 2021-09-07 13:00:41

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

Re: [SOLVED] simple bash script that opens all url in .txt file?

seth wrote:
ArchNewbieKernel wrote:

this is wrong because there is no "\r", is just the empty void after the link in the same line.

Don't argue with facts. You lose.
https://en.wikipedia.org/wiki/Newline

I give you on that but about the solution of this topic?

Offline

#15 2021-09-07 14:24:32

seth
Member
Registered: 2012-09-03
Posts: 49,951

Re: [SOLVED] simple bash script that opens all url in .txt file?

Fix the EOL, then use Trilby's oneliner correctly (see Slithery's comment)
You also want to overread the comments or pick lines starting w/ http explicitly.

while read line; do [[ "$line" = "http"* ]] && librewolf "$line"; done <  YT-SUBSCRIPTIONS.txt # afaics the binary is "librewolf" w/o CamelCasing

Offline

#16 2021-09-07 14:46:06

ArchNewbieKernel
Banned
Registered: 2020-09-25
Posts: 74

Re: [SOLVED] simple bash script that opens all url in .txt file?

seth wrote:

Fix the EOL, then use Trilby's oneliner correctly (see Slithery's comment)
You also want to overread the comments or pick lines starting w/ http explicitly.

while read line; do [[ "$line" = "http"* ]] && librewolf "$line"; done <  YT-SUBSCRIPTIONS.txt # afaics the binary is "librewolf" w/o CamelCasing

Your oneliner did it, thanks.

Offline

Board footer

Powered by FluxBB