LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash; reading values from a file (https://www.linuxquestions.org/questions/programming-9/bash%3B-reading-values-from-a-file-343482/)

bigearsbilly 07-28-2005 10:20 AM

this works...

Code:


while read line;do

  set -- $line                      ##  set $1 $2 $3 etc

  tag="$1"
  shift

  while [ $# -gt 1 ] ;do            ## while parameters left > 1
    desc="$desc $1"
    shift                            ## shift 'em all up one
  done

  status=$1                          ## should be one left here

  echo tag=$tag
  echo desc=$desc
  echo status=$status
  echo  "============"

  unset desc

done

data
Code:

tag1 this has three good
tag2 this has three no five  good
tag3 zero bad
tag5 this has lots and lots and lots  bad

result
Code:

bash 2 < data
tag=tag1
desc= this has three
status=good
============
tag=tag2
desc= this has three no five
status=good
============
tag=tag3
desc= zero
status=bad
============
tag=tag5
desc= this has lots and lots and lots
status=bad
============


schneidz 07-28-2005 02:07 PM

this is close:

threadid=343482

you basically want to tokenize your input


All times are GMT -5. The time now is 08:52 PM.