파일이 있어요 -
something
\title{\hypertarget{A64L}{A64L(3)}}
something
\title{\hypertarget{MALLOC}{MALLOC(3)}}
something
\title{\hypertarget{STRCMP}{STRCMP(3)}}
in 의 단어는 {}
무엇이든 될 수 있지만 Continuous 에서는 동일합니다 {}
.
난 갖길 원해
something
\title{\hypertarget{A64L}{A64L(3)}}
\addcontentsline{A64L}
something
\title{\hypertarget{MALLOC}{MALLOC(3)}}
\addcontentsline{MALLOC}
something
\title{\hypertarget{STRCMP}{STRCMP(3)}}
\addcontentsline{STRCMP}
따라해봤는데 실패했어요.
sed -e /\\\\title\{\\\\hypertarget\{.*\}\{.*\(3\)\}\}/a\\\\\\addcontentsline\{\&\} filename
이것은 확장입니다https://tex.stackexchange.com/questions/408244/how-to-make-toc-without-having-any-section-parts-name
답변1
정확히 무엇을 캡쳐하고 싶은지 모르겠지만,
$ sed 's/\\title{\\hypertarget\({[^}]*}\).*/&\n\\addcontentsline\1/' file
something
\title{\hypertarget{A64L}{A64L(3)}}
\addcontentsline{A64L}
something
\title{\hypertarget{MALLOC}{MALLOC(3)}}
\addcontentsline{MALLOC}
something
\title{\hypertarget{STRCMP}{STRCMP(3)}}
\addcontentsline{STRCMP}
답변2
j=`grep -o "{[0-9A-Z]\{4\}}" k1.txt | sed -r "s/\s+//g" | sed '/^$/d'`;
grep -B1 "$j" k1.txt | sed "/title/s/.*/&\n\\\addcontentsline$j/g";
for i in `grep -o "{[A-Z]\{6\}}" k1.txt`; do
grep -B1 $i k1.txt| sed "/title/s/.*/&\n\\\addcontentsline$i/g";
done
산출:
something
\title{\hypertarget{A64L}{A64L(3)}}
\addcontentsline{A64L}
something
\title{\hypertarget{MALLOC}{MALLOC(3)}}
\addcontentsline{MALLOC}
something
\title{\hypertarget{STRCMP}{STRCMP(3)}}
\addcontentsline{STRCMP}