How to fetch the string "Hi there" from the below array in unix

0

I only want to fetch Hi there and store it in a variable VAR1. So basically VAR1 should contain Hi there

VIEW_COL[1]="Hi there,USA,Y"

This is what i have tried so far.

Column_Display_Name=`echo ${VIEW_COL[$LoopViewCol]}|cut -d"," -f1|sed 's/^[ \t]*//;s/[ \t]*$//'`

But since there is a space between "hi" and "there" my command is not able to handle. Please help and let me know if i have asked something wrong in the question.

chikkada

Posted 2015-01-07T11:56:28.050

Reputation: 1

1This part echo ${VIEW_COL[$LoopViewCol]}|cut -d"," -f1 returns Hi there (if $LoopViewCol==1). What do you want/expect the sed part to do? – Nifle – 2015-01-07T12:05:40.053

Answers

1

If you're using bash, you can use parameter expansion:

echo ${VIEW_COL[1]%%,*}
Hi there

% means remove from the right, %% means greedily, ,* is the pattern to remove.

choroba

Posted 2015-01-07T11:56:28.050

Reputation: 14 741