Input data to a shell script [closed]

AFAI understand you want to use an array: read -r -a names Example: read -r -a names <<< “John Marry Sanford Saunders” echo “${names[0]}” # John echo “${names[1]}” # Marry echo “${names[2]}” # Sanford echo “${names[3]}” # Saunders

What does 2>&1 mean here?

Before talking about redirections i have the feeling that you need to understand a basic thing: Linux commands produce normal output and error output, and unix gives you the freedom to “redirect” each output to a separate “channel” , called file descriptors (fd). Channel/fd 1 is used for std ouput and Channel/fd 2 is used … Read more

Sort words and then the sentence including digits and characters in Shell scripting or perl scripting [closed]

The algorithm to sort this problem is simple, just like you said in your question description, sort characters in each word first, then sort these sorted-word again. Like this: $ echo heya64 this is21 a good89 day91 | perl -anE ‘say(join ” “, sort(map { join “”, sort split // } @F))’ 12is 19ady 46aehy … Read more

Get lines between two patterns

You would use sed for a task like that. It supports a syntax like from lines matching AAA print everything up to and including a line matching XXX. Alas your input is a bit ill-formed because the starting pattern AAA occurs twice without a matching XXX for the second AAA. sed default behavior is to … Read more