Re: Find a string in a file and add a sequential counter to that word
"dmt00000" <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
> 1 Class in COER 112
> Label "Microcomputer Operating Systems";
> 1 Class in COER 116
> Label "Microcomputer Hardware";
> 1 Class in COER 125
> Label "Seminar";
>
> I want it to ultimately look like this:
>
> 1 Class in COER 112
> Label 1 "Microcomputer Operating Systems";
> 1 Class in COER 116
> Label 2 "Microcomputer Hardware";
> 1 Class in COER 125
> Label 3 "Seminar";
>
sed '/Class/N;s/\n/JABBERWOCKY/' /tmp/test.in | \
sed = | \
sed 'N;s/\(^[0-9][0-9]*\)\n\(.*\)JABBERWOCKY\(.*Label\)\(.*\)/\2\
\3 \1\4/'
Tested.
But probably this is more sane:
awk '{sub(/Label /,"&"++x" ")};1' /tmp/test.in
-Derek