I have a variable ${value} and its contents are:

bigint_col, smallint_col,string_col,string_col,string_col, bigint_col, string_col,string_col,timestamp_col,timestamp_col,timestamp_col,timestamp_col

I want to replace only first bigint_col with my_col from the variable itself so that the new contents should look like this

my_col, smallint_col,string_col,string_col,string_col, bigint_col, string_col,string_col,timestamp_col,timestamp_col,timestamp_col,timestamp_col

I am looking some help to solve this.

  • printf "%s\n" "my_col,${value#*,}"...
    – jasonwryan
    Feb 24, 2016 at 8:25
  • 1
    echo "${value//bigint_col/my_col}" outputs contents of $value replacing all instances of bigint_col with my_col. To replace only the first instance, use ${value/bigint_col/my_col}.
    – DopeGhoti
    Feb 24, 2016 at 8:30
  • updated the question as per my desired output. Feb 24, 2016 at 8:33

1 Answer 1

echo "${value/bigint_col/my_col}"  # outputs contents of $value replacing the first instance of 'bigint_col' with 'my_col'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .