bash: awk write each match to a file and increment filename
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist
I tried it already with a while read loop, but that didn't work.
awk certificates
add a comment |
I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist
I tried it already with a while read loop, but that didn't work.
awk certificates
add a comment |
I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist
I tried it already with a while read loop, but that didn't work.
awk certificates
I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I can't figure out, how to seperate per match and make print create a new file each cert.
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ print > outputlist ' inputlist
I tried it already with a while read loop, but that didn't work.
awk certificates
awk certificates
edited Mar 12 at 19:26
Rui F Ribeiro
42k1483142
42k1483142
asked Mar 11 at 16:01
Mickey MazurekMickey Mazurek
83
83
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Give a try to this:
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist
I always have this page open aside when writing awk
script: Awk
Files generated:
$ ls certificate*
certificate1.txt certificate2.txt
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
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%2f505665%2fbash-awk-write-each-match-to-a-file-and-increment-filename%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Give a try to this:
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist
I always have this page open aside when writing awk
script: Awk
Files generated:
$ ls certificate*
certificate1.txt certificate2.txt
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
add a comment |
Give a try to this:
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist
I always have this page open aside when writing awk
script: Awk
Files generated:
$ ls certificate*
certificate1.txt certificate2.txt
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
add a comment |
Give a try to this:
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist
I always have this page open aside when writing awk
script: Awk
Files generated:
$ ls certificate*
certificate1.txt certificate2.txt
Give a try to this:
awk '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/ if ( $0 ~ /-----BEGIN CERTIFICATE-----/) nb++ ; print > "certificate" nb ".txt" ;' inputlist
I always have this page open aside when writing awk
script: Awk
Files generated:
$ ls certificate*
certificate1.txt certificate2.txt
edited Mar 12 at 7:46
answered Mar 11 at 16:14
Jay jargotJay jargot
97138
97138
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
add a comment |
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
This Looks great! I going to check it tomorrow. Need to hurry home, but thanks Forward for your help! I will reply to tomorrow with results :)
– Mickey Mazurek
Mar 11 at 16:20
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
It worked! thx for that. :) this was the trickiest part. At the beginning the Cert had no ---begin & end---- ... had to include it with sed, but that took Ages for me to figure out how to. I googled a lot, but I found no good explenation, because I didn't know, was it a record seperator, or do i Need some other Options and variables... such a brainf**** ^^
– Mickey Mazurek
Mar 12 at 8:17
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.
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%2f505665%2fbash-awk-write-each-match-to-a-file-and-increment-filename%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