I’ve got a file which is like this:
3 EOE
5 APPLE
6 NOBODY
i need to parse this and output all with ‘3’ in the first column into filename.3, ‘4’ into filename.4, etc… from the unix prompt
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.
Something like this should work (I haven’t tested it):
readwill read a line of text, then split it up on whitespace into “words”, like when you run a command. It will assign the first “word” to the first variable name (numin this case – which will get the number), the second “word” to the second variable name (rest), and so on. If it runs out of variables, it will append the remainder of the line to the last variable (rest, here).When
readprocesses a line successfully it returns zero, which is “success” in shell scripting, so thewhileloop will keep going, reading subsequent lines. Whenreadhits the end of the file, it will return 1, stopping thewhileloop.