Create text files from each link in a list?
I have a file with links like this:
http://domain.com/file_name1.mkv
http://domain.com/file_name2.mkv
http://domain.com/file_name3.mkv
... and so on.
I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?
I have a command that is doing something close but it creates only files with the names from words in a file:
sed -e 's/$/.strm/' file | xargs -d 'n' touch
files
add a comment |
I have a file with links like this:
http://domain.com/file_name1.mkv
http://domain.com/file_name2.mkv
http://domain.com/file_name3.mkv
... and so on.
I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?
I have a command that is doing something close but it creates only files with the names from words in a file:
sed -e 's/$/.strm/' file | xargs -d 'n' touch
files
add a comment |
I have a file with links like this:
http://domain.com/file_name1.mkv
http://domain.com/file_name2.mkv
http://domain.com/file_name3.mkv
... and so on.
I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?
I have a command that is doing something close but it creates only files with the names from words in a file:
sed -e 's/$/.strm/' file | xargs -d 'n' touch
files
I have a file with links like this:
http://domain.com/file_name1.mkv
http://domain.com/file_name2.mkv
http://domain.com/file_name3.mkv
... and so on.
I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?
I have a command that is doing something close but it creates only files with the names from words in a file:
sed -e 's/$/.strm/' file | xargs -d 'n' touch
files
files
asked 1 hour ago
user1800997
163
163
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/
tells awk to split the lines into fields using /
as a delimiter; $0
is the entire line, and $NF
is the value of the last field. The print statement executes for every line of the file.
awk -F/ '{print $0 > $NF}' < input
add a comment |
To elaborate your xargs
attempt
xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file
The first substitution f="${0##*/}"
removes the path components of the URL, while the second "${f%.*}.strm"
removes and replaces the extension.
Ex.
$ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
$ head *.strm
==> file_name1.strm <==
http://domain.com/file_name1.mkv
==> file_name2.strm <==
http://domain.com/file_name2.mkv
==> file_name3.strm <==
http://domain.com/file_name3.mkv
add a comment |
while read link; do
echo $link >$link.strm
done
Issues: The links contain/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
– Kusalananda
37 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491346%2fcreate-text-files-from-each-link-in-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/
tells awk to split the lines into fields using /
as a delimiter; $0
is the entire line, and $NF
is the value of the last field. The print statement executes for every line of the file.
awk -F/ '{print $0 > $NF}' < input
add a comment |
You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/
tells awk to split the lines into fields using /
as a delimiter; $0
is the entire line, and $NF
is the value of the last field. The print statement executes for every line of the file.
awk -F/ '{print $0 > $NF}' < input
add a comment |
You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/
tells awk to split the lines into fields using /
as a delimiter; $0
is the entire line, and $NF
is the value of the last field. The print statement executes for every line of the file.
awk -F/ '{print $0 > $NF}' < input
You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/
tells awk to split the lines into fields using /
as a delimiter; $0
is the entire line, and $NF
is the value of the last field. The print statement executes for every line of the file.
awk -F/ '{print $0 > $NF}' < input
answered 30 mins ago
Jeff Schaller
38.7k1053125
38.7k1053125
add a comment |
add a comment |
To elaborate your xargs
attempt
xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file
The first substitution f="${0##*/}"
removes the path components of the URL, while the second "${f%.*}.strm"
removes and replaces the extension.
Ex.
$ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
$ head *.strm
==> file_name1.strm <==
http://domain.com/file_name1.mkv
==> file_name2.strm <==
http://domain.com/file_name2.mkv
==> file_name3.strm <==
http://domain.com/file_name3.mkv
add a comment |
To elaborate your xargs
attempt
xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file
The first substitution f="${0##*/}"
removes the path components of the URL, while the second "${f%.*}.strm"
removes and replaces the extension.
Ex.
$ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
$ head *.strm
==> file_name1.strm <==
http://domain.com/file_name1.mkv
==> file_name2.strm <==
http://domain.com/file_name2.mkv
==> file_name3.strm <==
http://domain.com/file_name3.mkv
add a comment |
To elaborate your xargs
attempt
xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file
The first substitution f="${0##*/}"
removes the path components of the URL, while the second "${f%.*}.strm"
removes and replaces the extension.
Ex.
$ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
$ head *.strm
==> file_name1.strm <==
http://domain.com/file_name1.mkv
==> file_name2.strm <==
http://domain.com/file_name2.mkv
==> file_name3.strm <==
http://domain.com/file_name3.mkv
To elaborate your xargs
attempt
xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file
The first substitution f="${0##*/}"
removes the path components of the URL, while the second "${f%.*}.strm"
removes and replaces the extension.
Ex.
$ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
$ head *.strm
==> file_name1.strm <==
http://domain.com/file_name1.mkv
==> file_name2.strm <==
http://domain.com/file_name2.mkv
==> file_name3.strm <==
http://domain.com/file_name3.mkv
answered 26 mins ago
steeldriver
34.2k35083
34.2k35083
add a comment |
add a comment |
while read link; do
echo $link >$link.strm
done
Issues: The links contain/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
– Kusalananda
37 mins ago
add a comment |
while read link; do
echo $link >$link.strm
done
Issues: The links contain/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
– Kusalananda
37 mins ago
add a comment |
while read link; do
echo $link >$link.strm
done
while read link; do
echo $link >$link.strm
done
answered 40 mins ago
Erwan
1994
1994
Issues: The links contain/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
– Kusalananda
37 mins ago
add a comment |
Issues: The links contain/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
– Kusalananda
37 mins ago
Issues: The links contain
/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.– Kusalananda
37 mins ago
Issues: The links contain
/
, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.– Kusalananda
37 mins ago
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491346%2fcreate-text-files-from-each-link-in-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown