1

I have those lines from db dump

INSERT INTO db1 VALUES ('2', '33', '3', '1975', '3', '5', '1');
INSERT INTO db1 VALUES ('4', '23544', '1', '1987', '3', '1', '1');
INSERT INTO db1 VALUES ('2', '343', '3', '1975', '3', '5', '1');
INSERT INTO db1 VALUES ('4', '21', '1', '1987', '3', '1', '1');

As you seen the second filed is 33, 23544 ,343 using the ' '.

I want to substitute with awk with a numeric increasing filed (1,2,3..), I know how to do using $2++,but I don't know how to pass the ' as a field separator.

Using this syntax give me error:

awk 'BEGIN { FS = "' '" } ; { print $2 }'
2

What about

awk -F\' '{print $2}'

Just escape the '

Getting the output field separator back takes a bit more quoting, but can be done by setting OFS inside awk. Putting it all together with your question it would look like (with much appreciated cleanup from @Peter.O):

awk -F\' -vOFS=\' '{$2++;print}'
  • 1
    Or: awk -F\' -vOFS=\' '{$2++;print}' – Peter.O May 19 '15 at 3:14

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.