I am parsing a file to get the selected string and build into a single line, however, I don’t know how to do it(as shown in //add…) in shell scripts
while read line
do
tt=`echo $line | cut -d'|' -f2 | cut -d'"' -f1`
//add a $total = add all tt parts into a big string seperate by ", "
done < tmp_file
echo $total >> outfile
thank you
You append in the shell using assignment and variable expansion:
The curly braces (
{}) aren’t necessary in this case but I find they help distinguish variables when they’re next to each other like this.This will give you a leading “, “. You can work around it like this:
The
${variable:+value}construct only expands tovalueifvariableis set.