Home » Questions » Computers [ Ask a new question ]

how to use grep, sed, and awk to parse tags?

how to use grep, sed, and awk to parse tags?

I want to write a script that finds a open/close tag pair in a text file and prepends a fixed string to each line between the pair. I figure I use grep to find the tag line numbers and either awk or sed to place the tags, however, I'm not sure how exactly to do it.

Asked by: Guest | Views: 192
Total answers/comments: 2
Guest [Entry]

"In awk:

START {noprefix=""true""}
/<close tag regex>/ {noprefix=""true""}
noprefix==""false"" {print ""prefix"", $0}
noprefix==""true"" {print $0}
/<open tag regex>/ {noprefix=""false""}"
Guest [Entry]

You should consider using yacc for it. It is NOT possible to do this with sed, awk or grep without a considerable amount of effort. As for learning yacc, it wouldn't take more time than it did for learning sed/awk/grep. And it will be really easy that way.