tkumaran
tkumaran

Reputation: 111

string replacement in shell script

How to replace the below DECIMAL data type with DOUBLE using shell script?

Source String:

.
.
GROSS_AMOUNT  DECIMAL(11, 2)
.
.

Result Should be:

.
.
GROSS_AMOUNT  DOUBLE
.
.

Upvotes: 0

Views: 51

Answers (2)

Arjun Mathew Dan
Arjun Mathew Dan

Reputation: 5318

From within shell script:

#!/bin/bash

str="...GROSS_AMOUNT DECIMAL(11, 2)..."
str=$(sed 's/DECIMAL(.*)/DOUBLE/' <<< $str)
echo $str

This will output: ...GROSS_AMOUNT DOUBLE...

Using sed, replace DECIMAL(11, 2) with whatever (in this case, DOUBLE).

Upvotes: 0

user4386814
user4386814

Reputation:

awk 'BEGIN{FS=OFS="  "}$2{$2="DOUBLE"}1'
  • Set Field Separator and Output Field Separator to two spaces
  • If Field 2 exists, set it to DOUBLE
  • Print

Upvotes: 1

Related Questions