Wie multipliziere ich eine Zahl mit 2 mit SED?Linux

Linux verstehen
Anonymous
 Wie multipliziere ich eine Zahl mit 2 mit SED?

Post by Anonymous »

Ich habe eine Textdatei mit dem Namen test.sql. Wie kann ich den SED -Befehl verwenden, um die Zahlen in char und varchar mit 2 zu multiplizieren? Vielen Dank.

Code: Select all

create table test_table
(
test01 char(40),
test02 date,
test03 varchar(80),
test04 decimal(9,2) not null ,
test05 varchar(100),
test06 serial not null
);

< /code>
Ich hoffe, den Befehl SED zu verwenden, um den Inhalt in Folgendes zu ändern: < /p>
create table test_table
(
test01 char(80),
test02 date,
test03 varchar(160),
test04 decimal(9,2) not null ,
test05 varchar(200),
test06 serial not null
);
< /code>
Ich habe die folgenden Befehle ohne Erfolg ausprobiert. < /p>
sed -E 's:(char|varchar|nvarchar)\(([0-9]+)\):print  \1\(\2 * 2\):g ' test.sql
< /code>
sed -E "s/(char|varchar)\(([0-9]+)\)/\1\(echo "\\2*2"|bc\)/g" test.sql
< /code>
[root@owen-test ~]# sed -E 's:(char|varchar|nvarchar)\(([0-9]+)\):print  \1\(\2 * 2\):g ' test.sql
create table test_table
(
test01 print  char(40 * 2),
test02 date,
test03 print  varchar(80 * 2),
test04 decimal(9,2) not null ,
test05 print  varchar(100 * 2),
test06 serial not null
);
< /code>

[root@owen-test ~]# sed -E "s/(char|varchar)\(([0-9]+)\)/\1\(echo "\\2*2"|bc\)/g" test.sql
create table test_table
(
test01 char(echo 40*2|bc),
test02 date,
test03 varchar(echo 80*2|bc),
test04 decimal(9,2) not null ,
test05 varchar(echo 100*2|bc),
test06 serial not null
);

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post