Discussion:
sets in bash script
Ted Yu
2014-04-01 01:44:36 UTC
Permalink
Hi,
I wanted to search for a small collection of Strings in log file.
Here is sample of Strings:

util.StreamUtils
visibility.DefaultScanLabelGenerator
expression.ExpressionNode
expression.LeafExpressionNode
expression.NonLeafExpressionNode

I found this: sets in linux Bash - Stack Overflow
However, I don't know how to iterate over the set.

declare -A classes
cat $1 | while read line; do
  classes[$line]=1
done
for var in "${classes[@]}" do
  echo $var
done

I got the following:

./filter-log.sh: line 3: client.Get: syntax error: invalid arithmetic operator (error token is ".Get")
./filter-log.sh: line 6: syntax error near unexpected token `echo'
./filter-log.sh: line 6: `  echo $var'

Help would be appreciated.
Nimret Sandhu
2014-04-01 06:50:28 UTC
Permalink
Hi Ted,

Though this isn't quite Java specific you may want to look into grep or
sed/awk for searching for matches in files. Groovy is another option.

cheers,
-
Nimret Sandhu
http://www.nimret.org
Post by Ted Yu
Hi,
I wanted to search for a small collection of Strings in log file.
util.StreamUtils
visibility.DefaultScanLabelGenerator
expression.ExpressionNode
expression.LeafExpressionNode
expression.NonLeafExpressionNode
I found this: sets in linux Bash - Stack Overflow<http://stackoverflow.com/questions/19143528/sets-in-linux-bash>
However, I don't know how to iterate over the set.
declare -A classes
cat $1 | while read line; do
classes[$line]=1
done
echo $var
done
./filter-log.sh: line 3: client.Get: syntax error: invalid arithmetic
operator (error token is ".Get")
./filter-log.sh: line 6: syntax error near unexpected token `echo'
./filter-log.sh: line 6: ` echo $var'
Help would be appreciated.
Loading...