Naveen Srikanth
Naveen Srikanth

Reputation: 789

Adding extra string to comma separated values using shell

Please help using shell script for below statement

My input is below

a=abc,def,ghi

My output should be as below

a=h.abc,h.def,h.ghi

How can I achieve this in shell scripting please help

Upvotes: 1

Views: 69

Answers (1)

Vishnu T S
Vishnu T S

Reputation: 3914

Use this

export IFS=","
    words="abc,def,ghi"
    for word in $words; do
      echo "h.$word"
    done

If you want to print output in the same line use echo -n

Upvotes: 1

Related Questions