0

I have a text file having contents in format...

File=/opt/mgtservices/probes/logs is_SS_File=no is_Log=yes Output_File=probes_logs

This can have around 1k records. I am reading line by line from a file.

while read -r line
do
  if [ $SS_SERVER -eq 0 ]
  then
    arr=$(echo "$line" | tr ' =' "\n")
    echo $arr[1]
    #do something
  elif [[ $SS_SERVER -eq 1 && "$line" =~ "is_SS_File=\"no\"" ]]
  then
    #do something else
  fi
done < "$filename"

I am expecting that arr should be an array, so that I can get output as:

arr[1]=File
arr[2]=/opt/mgtservices/probes/logs
arr[3]=is_SS_File
and so on...

Which I am not getting here. arr[1] is giving me complete line without "=" I want to use 2 delimiters "space" and "=".

4
  • What is the meaning and significance of SS_SERVER and where is it being set? Commented Mar 11, 2015 at 9:01
  • @tripleee...SS_SERVER is a flag which I can get from calling function. It can be 0 or 1. Commented Mar 11, 2015 at 9:04
  • Then it's not really relevant to your question, is it? Commented Mar 11, 2015 at 9:05
  • @triplee yes, you can say like that, basically my intention is to split string with multiple delimiters into array Commented Mar 11, 2015 at 9:15

1 Answer 1

1

Depending on what you are trying to accomplish try this:

tr ' =' '\n ' <"$file" |
while read keyword value; do
    : you get one keyword and its value at a time now
done

or maybe

while IFS=' =' read -a arr; do
    : arr[0] is first keyword
    : arr[1] is its value
    : arr[2] is second keyword
    : etc
done <"$file"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.