Reputation: 519
I have hundreds of lines like this one:
INSERT INTO table1 VALUES (5566, 1979, 'Montag', '06:00', '19:00', 1, 'ON', NULL
I need to add to the first number 5566
another number, let say 50
and this in each line.
There is many ways how to get the first number with sed or awk but how can I perform the arithmetic and replace the number?
Any hints?
Upvotes: 1
Views: 91
Reputation: 785611
You can do use this awk:
s='INSERT INTO table1 VALUES (5566, 1979, 'Montag', '06:00', '19:00', 1, 'ON', NULL'
echo "$s"|awk '{sub(/[^0-9]+/, "", $5); $5+=50; $5="(" $5 ","} 1'
INSERT INTO table1 VALUES (5616, 1979, Montag, 06:00, 19:00, 1, ON, NULL
Upvotes: 2