Ubuntu Bash: Get text between 2 colons from a text file [duplicate]












0
















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.










share|improve this question













marked as duplicate by emix, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 you TestUser.

    – User123
    Jan 3 at 10:19











  • Thank you very much

    – d0neall
    Jan 3 at 10:35
















0
















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.










share|improve this question













marked as duplicate by emix, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 you TestUser.

    – User123
    Jan 3 at 10:19











  • Thank you very much

    – d0neall
    Jan 3 at 10:35














0












0








0









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.










share|improve this question















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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 10:17









d0nealld0neall

376




376




marked as duplicate by emix, tripleee bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 you TestUser.

    – 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











  • 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












1 Answer
1






active

oldest

votes


















0














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 make cut 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.






share|improve this answer
























  • Ok thank you guys!

    – d0neall
    Jan 3 at 10:27


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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 make cut 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.






share|improve this answer
























  • Ok thank you guys!

    – d0neall
    Jan 3 at 10:27
















0














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 make cut 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.






share|improve this answer
























  • Ok thank you guys!

    – d0neall
    Jan 3 at 10:27














0












0








0







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 make cut 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.






share|improve this answer













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 make cut 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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 10:19









Kamil CukKamil Cuk

12.5k1529




12.5k1529













  • 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





Ok thank you guys!

– d0neall
Jan 3 at 10:27





Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas