How to get specific words by index in a line bash
up vote 0 down vote favorite I have a script that takes parameters such as: script.sh 1 3 I want to then go through a text file and print out the first and third words from each line. I have simply no idea how to do this. If anyone could help I'd really appreciate it... This is what I currently have: counter=0 wordcounter=0 param=$(echo "$3" | tr , " ") words() for word in $1; do for col in $param; do if [ $wordcounter -eq $col ]; then echo $word fi done done wordcounter=$((wordcounter + 1)) eachline() tr , " ") for word in $newline; do if [ $counter -gt 3 ]; then echo "$word" fi counter=$((counter + 1)) done if [ $counter -gt 0 ]; then words "$newline" fi counter=$((counter + 1)) while read line; do eachline $line done < company/employee.txt bash shell text share | improve this question edited Nov 10 at 12:57 asked Nov 10 at 12:11 Raph117 152 1 10