If I have a string variable who’s value is "john is 17 years old" how do I tokenize this using spaces as the delimeter? Would I use awk?
If I have a string variable who’s value is john is 17 years old
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the shell’s automatic tokenization of unquoted variables:
If you want to change the delimiter you can set the
$IFSvariable, which stands for internal field separator. The default value of$IFSis" \t\n"(space, tab, newline).(Note that in this second example I added parentheses around the second line. This creates a sub-shell so that the change to
$IFSdoesn’t persist. You generally don’t want to permanently change$IFSas it can wreak havoc on unsuspecting shell commands.)