0

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 '16 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 '16 at 8:30
  • updated the question as per my desired output. – Sandeep Singh Feb 24 '16 at 8:33
5
echo "${value/bigint_col/my_col}"  # outputs contents of $value replacing the first instance of 'bigint_col' with 'my_col'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.