Ubuntu Bash: Get text between 2 colons from a text file [duplicate]
This question already has an answer here:
Bash string explode [duplicate]
4 answers
I am a beginner in Ubuntu bash and couldn´t find a solution after searching for hours.
I have a config file with lines like:
u:TestUser:rw:/home/temp/testFolder
I want to give the user the rights to this folder, but first I have to check if the user exists and if not, create that user.
The only problem I have is extracting "TestUser" from between the colons. With that I could check if the user exists with /etc/passwd.
bash ubuntu
marked as duplicate by emix, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 10:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Bash string explode [duplicate]
4 answers
I am a beginner in Ubuntu bash and couldn´t find a solution after searching for hours.
I have a config file with lines like:
u:TestUser:rw:/home/temp/testFolder
I want to give the user the rights to this folder, but first I have to check if the user exists and if not, create that user.
The only problem I have is extracting "TestUser" from between the colons. With that I could check if the user exists with /etc/passwd.
bash ubuntu
marked as duplicate by emix, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 10:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
awk -F":" '{print $2}' config_file
would give youTestUser
.
– User123
Jan 3 at 10:19
Thank you very much
– d0neall
Jan 3 at 10:35
add a comment |
This question already has an answer here:
Bash string explode [duplicate]
4 answers
I am a beginner in Ubuntu bash and couldn´t find a solution after searching for hours.
I have a config file with lines like:
u:TestUser:rw:/home/temp/testFolder
I want to give the user the rights to this folder, but first I have to check if the user exists and if not, create that user.
The only problem I have is extracting "TestUser" from between the colons. With that I could check if the user exists with /etc/passwd.
bash ubuntu
This question already has an answer here:
Bash string explode [duplicate]
4 answers
I am a beginner in Ubuntu bash and couldn´t find a solution after searching for hours.
I have a config file with lines like:
u:TestUser:rw:/home/temp/testFolder
I want to give the user the rights to this folder, but first I have to check if the user exists and if not, create that user.
The only problem I have is extracting "TestUser" from between the colons. With that I could check if the user exists with /etc/passwd.
This question already has an answer here:
Bash string explode [duplicate]
4 answers
bash ubuntu
bash ubuntu
asked Jan 3 at 10:17
d0nealld0neall
376
376
marked as duplicate by emix, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 10:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by emix, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 3 at 10:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
awk -F":" '{print $2}' config_file
would give youTestUser
.
– User123
Jan 3 at 10:19
Thank you very much
– d0neall
Jan 3 at 10:35
add a comment |
awk -F":" '{print $2}' config_file
would give youTestUser
.
– User123
Jan 3 at 10:19
Thank you very much
– d0neall
Jan 3 at 10:35
awk -F":" '{print $2}' config_file
would give you TestUser
.– User123
Jan 3 at 10:19
awk -F":" '{print $2}' config_file
would give you TestUser
.– User123
Jan 3 at 10:19
Thank you very much
– d0neall
Jan 3 at 10:35
Thank you very much
– d0neall
Jan 3 at 10:35
add a comment |
1 Answer
1
active
oldest
votes
You need to "cut" the text between delimiters. A job for cut
:
cut -d: -f2 /etc/passwd
-d:
- set's the delimeter to:
(default is tab)
-f2
- will makecut
print only the second field frim the file - ie. username
But to check if a user exists on a system, see superuser - Find out if user name exists and use id
command.
Ok thank you guys!
– d0neall
Jan 3 at 10:27
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to "cut" the text between delimiters. A job for cut
:
cut -d: -f2 /etc/passwd
-d:
- set's the delimeter to:
(default is tab)
-f2
- will makecut
print only the second field frim the file - ie. username
But to check if a user exists on a system, see superuser - Find out if user name exists and use id
command.
Ok thank you guys!
– d0neall
Jan 3 at 10:27
add a comment |
You need to "cut" the text between delimiters. A job for cut
:
cut -d: -f2 /etc/passwd
-d:
- set's the delimeter to:
(default is tab)
-f2
- will makecut
print only the second field frim the file - ie. username
But to check if a user exists on a system, see superuser - Find out if user name exists and use id
command.
Ok thank you guys!
– d0neall
Jan 3 at 10:27
add a comment |
You need to "cut" the text between delimiters. A job for cut
:
cut -d: -f2 /etc/passwd
-d:
- set's the delimeter to:
(default is tab)
-f2
- will makecut
print only the second field frim the file - ie. username
But to check if a user exists on a system, see superuser - Find out if user name exists and use id
command.
You need to "cut" the text between delimiters. A job for cut
:
cut -d: -f2 /etc/passwd
-d:
- set's the delimeter to:
(default is tab)
-f2
- will makecut
print only the second field frim the file - ie. username
But to check if a user exists on a system, see superuser - Find out if user name exists and use id
command.
answered Jan 3 at 10:19
Kamil CukKamil Cuk
12.5k1529
12.5k1529
Ok thank you guys!
– d0neall
Jan 3 at 10:27
add a comment |
Ok thank you guys!
– d0neall
Jan 3 at 10:27
Ok thank you guys!
– d0neall
Jan 3 at 10:27
Ok thank you guys!
– d0neall
Jan 3 at 10:27
add a comment |
awk -F":" '{print $2}' config_file
would give youTestUser
.– User123
Jan 3 at 10:19
Thank you very much
– d0neall
Jan 3 at 10:35