try this (gawk is needed)
awk '{a=gensub(/.*#([0-9]+)(\").*/,"\\1","g",$0);if(a~/[0-9]+/) {gsub(/[0-9]+\"/,a+11"\"",$0);}print $0}' YourFile
test with your example:
kent$ echo '(bookmarks
("Chapter 1 Introduction 1" "#1"
("1.1 Problem Statement and Basic Definitions 2" "#2")
("Exercises 30" "#30")
("Notes and References 34" "#34"))
)
'|awk '{a=gensub(/.*#([0-9]+)(\").*/,"\\1","g",$0);if(a~/[0-9]+/) {gsub(/[0-9]+\"/,a+11"\"",$0);}print $0}'
(bookmarks
("Chapter 1 Introduction 12" "#12"
("1.1 Problem Statement and Basic Definitions 13" "#13")
("Exercises 41" "#41")
("Notes and References 45" "#45"))
)
note that this command won't work if the two numbers e.g. 1" and "#1" are different. or there are more numbers in same line with this pattern. e.g. 23" ...32"..."#123" in one line.
UPDATE
since @Tim (OP) said the number followed by "
in same line could be different, I did some changes on my previous solution, and make it work for your new example.
btw, from the example I feel that it could be a table of content structure, I don't see how come the two numbers could be different. first would be the printed page number, and 2nd with # would be the page index. am I right?
anyway, you know your reqirement best. now the new solution, still with gawk (I break the command into lines to make it easier to read):
awk 'BEGIN{FS=OFS="\" \"#"}{if(NF<2){print;next;}
a=gensub(/.* ([0-9]+)$/,"\\1","g",$1);
b=gensub(/([0-9]+)\"/,"\\1","g",$2);
gsub(/[0-9]+$/,a+11,$1);
gsub(/^[0-9]+/,b+11,$2);
print $1,$2
}' yourFile
test with your new example:
kent$ echo '(bookmarks
("Chapter 1 Introduction 1" "#1"
("1.1 Problem Statement and Basic Definitions 23" "#2")
("Exercises 31" "#30")
("Notes and References 42" "#34"))
)
'|awk 'BEGIN{FS=OFS="\" \"#"}{if(NF<2){print;next;}
a=gensub(/.* ([0-9]+)$/,"\\1","g",$1);
b=gensub(/([0-9]+)\"/,"\\1","g",$2);
gsub(/[0-9]+$/,a+11,$1);
gsub(/^[0-9]+/,b+11,$2);
print $1,$2
}'
(bookmarks
("Chapter 1 Introduction 12" "#12"
("1.1 Problem Statement and Basic Definitions 34" "#13")
("Exercises 42" "#41")
("Notes and References 53" "#45"))
)
EIDT2 based on @Tim 's comment
(1) does FS=OFS="\" \"#" mean the separator of field in both input and
output is double quote, space, double quote and #? why specify double
quote twice?
you are right for the separator in both input and output part. it defined separator as:
" "#
there are two double quotes, because it is easier to catch the two numbers you want(based on your example input).
(2) in /.* ([0-9]+)$/, does $ mean the end of the string?
exactly!
(3) in the third argument of gensub(), what is the difference between
"g" and "G"? there is no difference between G and g. check this out:
gensub(regexp, replacement, how [, target]) #
Search the target string target for matches of the regular expression regexp. If how is a string beginning with ‘g’ or ‘G’ (short for “global”), then replace all matches of regexp with replacement.
this is from http://www.gnu.org/s/gawk/manual/html_node/String-Functions.html. you can read to get detailed usage of gensub.