Find only GUIDs in file - Bash
I have a file that might contain GUIDs (their canonical textual representation).
I want to do an action for each GUID in the file. It might contain any number of GUIDs.
I have already a file ready for reading. How do I spot the GUIDS?
I know I need to use while read FILENAME
An example of my file :
GUIDs
--------------------------------------
cf6e328c-c918-4d2f-80d3-71ecaf09bf7b
91d523b0-4926-456e-a9d2-ade713f5b07f
(2 rows)
// THERE IS AN EMPTY LINE HERE AFTER NUMBER OF ROWS
bash shell-script scripting wildcards
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 2 more comments
I have a file that might contain GUIDs (their canonical textual representation).
I want to do an action for each GUID in the file. It might contain any number of GUIDs.
I have already a file ready for reading. How do I spot the GUIDS?
I know I need to use while read FILENAME
An example of my file :
GUIDs
--------------------------------------
cf6e328c-c918-4d2f-80d3-71ecaf09bf7b
91d523b0-4926-456e-a9d2-ade713f5b07f
(2 rows)
// THERE IS AN EMPTY LINE HERE AFTER NUMBER OF ROWS
bash shell-script scripting wildcards
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Post your sample file.
– Tuyen Pham
42 mins ago
You're looking for any digit(s) from 0 to 10k, in any format? Or what exactly
– Xen2050
41 mins ago
I wrote a file as example
– MathEnthusiast
40 mins ago
What's the action you want to perform? It alters the possible solution
– roaima
38 mins ago
I need to run a command and then wait 5 seconds
– MathEnthusiast
37 mins ago
|
show 2 more comments
I have a file that might contain GUIDs (their canonical textual representation).
I want to do an action for each GUID in the file. It might contain any number of GUIDs.
I have already a file ready for reading. How do I spot the GUIDS?
I know I need to use while read FILENAME
An example of my file :
GUIDs
--------------------------------------
cf6e328c-c918-4d2f-80d3-71ecaf09bf7b
91d523b0-4926-456e-a9d2-ade713f5b07f
(2 rows)
// THERE IS AN EMPTY LINE HERE AFTER NUMBER OF ROWS
bash shell-script scripting wildcards
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a file that might contain GUIDs (their canonical textual representation).
I want to do an action for each GUID in the file. It might contain any number of GUIDs.
I have already a file ready for reading. How do I spot the GUIDS?
I know I need to use while read FILENAME
An example of my file :
GUIDs
--------------------------------------
cf6e328c-c918-4d2f-80d3-71ecaf09bf7b
91d523b0-4926-456e-a9d2-ade713f5b07f
(2 rows)
// THERE IS AN EMPTY LINE HERE AFTER NUMBER OF ROWS
bash shell-script scripting wildcards
bash shell-script scripting wildcards
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 23 mins ago
Stéphane Chazelas
301k55564916
301k55564916
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 46 mins ago
MathEnthusiastMathEnthusiast
183
183
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
MathEnthusiast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Post your sample file.
– Tuyen Pham
42 mins ago
You're looking for any digit(s) from 0 to 10k, in any format? Or what exactly
– Xen2050
41 mins ago
I wrote a file as example
– MathEnthusiast
40 mins ago
What's the action you want to perform? It alters the possible solution
– roaima
38 mins ago
I need to run a command and then wait 5 seconds
– MathEnthusiast
37 mins ago
|
show 2 more comments
Post your sample file.
– Tuyen Pham
42 mins ago
You're looking for any digit(s) from 0 to 10k, in any format? Or what exactly
– Xen2050
41 mins ago
I wrote a file as example
– MathEnthusiast
40 mins ago
What's the action you want to perform? It alters the possible solution
– roaima
38 mins ago
I need to run a command and then wait 5 seconds
– MathEnthusiast
37 mins ago
Post your sample file.
– Tuyen Pham
42 mins ago
Post your sample file.
– Tuyen Pham
42 mins ago
You're looking for any digit(s) from 0 to 10k, in any format? Or what exactly
– Xen2050
41 mins ago
You're looking for any digit(s) from 0 to 10k, in any format? Or what exactly
– Xen2050
41 mins ago
I wrote a file as example
– MathEnthusiast
40 mins ago
I wrote a file as example
– MathEnthusiast
40 mins ago
What's the action you want to perform? It alters the possible solution
– roaima
38 mins ago
What's the action you want to perform? It alters the possible solution
– roaima
38 mins ago
I need to run a command and then wait 5 seconds
– MathEnthusiast
37 mins ago
I need to run a command and then wait 5 seconds
– MathEnthusiast
37 mins ago
|
show 2 more comments
1 Answer
1
active
oldest
votes
With the GNU implementation of grep (or compatible):
<your-file grep -Eo '<[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}>' |
while IFS= read -r guid; do
your-action "$guid"
sleep 5
done
GNU grep has a -o option that prints the non-empty matches of the regular expression.
Its regular expressions, like in ex/vi support < and > word-boundary operators. They match on the transition between a non-word and word character and between a word and non-word character respectively (where word characters are alphanumerics or underscore). That's to guard against matching on things like:
aaaaaaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaaaaaa
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (likegrephere) which support extensions like that-oand<(<was in SysVgrepbefore GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular,-ois found in many other implementations.
– Stéphane Chazelas
26 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
});
}
});
MathEnthusiast is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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%2f494546%2ffind-only-guids-in-file-bash%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
With the GNU implementation of grep (or compatible):
<your-file grep -Eo '<[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}>' |
while IFS= read -r guid; do
your-action "$guid"
sleep 5
done
GNU grep has a -o option that prints the non-empty matches of the regular expression.
Its regular expressions, like in ex/vi support < and > word-boundary operators. They match on the transition between a non-word and word character and between a word and non-word character respectively (where word characters are alphanumerics or underscore). That's to guard against matching on things like:
aaaaaaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaaaaaa
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (likegrephere) which support extensions like that-oand<(<was in SysVgrepbefore GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular,-ois found in many other implementations.
– Stéphane Chazelas
26 mins ago
add a comment |
With the GNU implementation of grep (or compatible):
<your-file grep -Eo '<[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}>' |
while IFS= read -r guid; do
your-action "$guid"
sleep 5
done
GNU grep has a -o option that prints the non-empty matches of the regular expression.
Its regular expressions, like in ex/vi support < and > word-boundary operators. They match on the transition between a non-word and word character and between a word and non-word character respectively (where word characters are alphanumerics or underscore). That's to guard against matching on things like:
aaaaaaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaaaaaa
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (likegrephere) which support extensions like that-oand<(<was in SysVgrepbefore GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular,-ois found in many other implementations.
– Stéphane Chazelas
26 mins ago
add a comment |
With the GNU implementation of grep (or compatible):
<your-file grep -Eo '<[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}>' |
while IFS= read -r guid; do
your-action "$guid"
sleep 5
done
GNU grep has a -o option that prints the non-empty matches of the regular expression.
Its regular expressions, like in ex/vi support < and > word-boundary operators. They match on the transition between a non-word and word character and between a word and non-word character respectively (where word characters are alphanumerics or underscore). That's to guard against matching on things like:
aaaaaaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaaaaaa
With the GNU implementation of grep (or compatible):
<your-file grep -Eo '<[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}>' |
while IFS= read -r guid; do
your-action "$guid"
sleep 5
done
GNU grep has a -o option that prints the non-empty matches of the regular expression.
Its regular expressions, like in ex/vi support < and > word-boundary operators. They match on the transition between a non-word and word character and between a word and non-word character respectively (where word characters are alphanumerics or underscore). That's to guard against matching on things like:
aaaaaaaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaaaaaaaaaaa
edited 21 mins ago
answered 38 mins ago
Stéphane ChazelasStéphane Chazelas
301k55564916
301k55564916
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (likegrephere) which support extensions like that-oand<(<was in SysVgrepbefore GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular,-ois found in many other implementations.
– Stéphane Chazelas
26 mins ago
add a comment |
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (likegrephere) which support extensions like that-oand<(<was in SysVgrepbefore GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular,-ois found in many other implementations.
– Stéphane Chazelas
26 mins ago
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Can you please explain? What is that "<" in the beginning ? Also - what is GNU tools ? Can we assume my file name is GUIDS.TXT ?
– MathEnthusiast
36 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
Also - what is GNU tools ?
– MathEnthusiast
34 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (like
grep here) which support extensions like that -o and < (< was in SysV grep before GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular, -o is found in many other implementations.– Stéphane Chazelas
26 mins ago
@MathEnthusiast, see edit. The GNU project is an effort by the Free Software Foundation to provide with a FLOSS reimplementation of Unix. Some people confuse it with Linux as GNU systems generally use Linux as their kernel. They have written extended versions of the Unix utilities (like
grep here) which support extensions like that -o and < (< was in SysV grep before GNU's). GNU utilities are now more common than the original versions, and many other non-GNU implementations have copied some of the GNU extensions. In particular, -o is found in many other implementations.– Stéphane Chazelas
26 mins ago
add a comment |
MathEnthusiast is a new contributor. Be nice, and check out our Code of Conduct.
MathEnthusiast is a new contributor. Be nice, and check out our Code of Conduct.
MathEnthusiast is a new contributor. Be nice, and check out our Code of Conduct.
MathEnthusiast is a new contributor. Be nice, and check out our Code of Conduct.
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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%2f494546%2ffind-only-guids-in-file-bash%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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
Post your sample file.
– Tuyen Pham
42 mins ago
You're looking for any digit(s) from 0 to 10k, in any format? Or what exactly
– Xen2050
41 mins ago
I wrote a file as example
– MathEnthusiast
40 mins ago
What's the action you want to perform? It alters the possible solution
– roaima
38 mins ago
I need to run a command and then wait 5 seconds
– MathEnthusiast
37 mins ago