AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 413562
Accepted
alhelal
alhelal
Asked: 2017-12-29 16:59:10 +0800 CST2017-12-29 16:59:10 +0800 CST 2017-12-29 16:59:10 +0800 CST

Substituindo uma string diferente por uma nova string diferente que segue um padrão

  • 772

Eu tenho

\title{A64L(3)}
somethings
\textbf{a64l}()
\title{MALLOC(3)}
somethings
\textbf{malloc}()  

Eu quero

\title{\hypertarget{a64l}{A64L(3)}}
somethings
\textbf{\hyperlink{a64l}{a64l}}()
\title{\hypertarget{malloc}{MALLOC(3)}}
somethings
\textbf{\hyperlink{malloc}{malloc}}()  

ou

\title{\hypertarget{a64l}{A64L}(3)}
somethings
\textbf{\hyperlink{a64l}{a64l}}()
\title{\hypertarget{malloc}{MALLOC}(3)}
somethings
\textbf{\hyperlink{malloc}{malloc}}()

Estes são arquivos de amostra. Pode haver qualquer coisa em vez de A64Le MALLOC, mas siga o padrão (por exemplo \title{new_word}).

Eu tenho que fazer isso para obter os recursos descritos https://tex.stackexchange.com/questions/407884/how-to-make-a-title-as-link-target
Eu prefiro vim, sed, awk.

Sua resposta deve funcionar para seguir também-

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
    \usepackage{xltxtra,xunicode}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
  \newcommand{\euro}{€}
\fi
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
\usepackage{longtable,booktabs}
\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={},
            pdftitle={A64L(3)},
            colorlinks=true,
            citecolor=blue,
            urlcolor=blue,
            linkcolor=magenta,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\setcounter{secnumdepth}{0}
\usepackage{pagecolor}

% Set background colour (of the page)
\definecolor{weirdbgcolor}{HTML}{FCF4F0}
\pagecolor{weirdbgcolor}

% Make bold text appear in a particular colour
\definecolor{boldcolor}{HTML}{6E0002}
\let\realtextbf=\textbf
\renewcommand{\textbf}[1]{\textcolor{boldcolor}{\realtextbf{#1}}}

% Use underlines instead of emphasis (ugh)
\renewcommand{\emph}[1]{\underline{#1}}
\hypersetup{breaklinks=false}

% % Use fixed-width font by default
% \renewcommand*\familydefault{\ttdefault}

\title{A64L(3)}
\author{}
\date{}

\begin{document}
\maketitle

\begin{longtable}[c]{@{}lll@{}}
\toprule\addlinespace
A64L(3) & Linux Programmer's Manual & A64L(3)
\\\addlinespace
\bottomrule
\end{longtable}

\hyperdef{}{NAME}{\section{\hyperref[NAME]{NAME}}\label{NAME}}

a64l, l64a - convert between long and base-64

\hyperdef{}{SYNOPSIS}{\section{\hyperref[SYNOPSIS]{SYNOPSIS}}\label{SYNOPSIS}}

\textbf{\#include \textless{}stdlib.h\textgreater{}}

~

\textbf{long a64l(char *}\emph{str64}\textbf{);}

~

\textbf{char *l64a(long}\emph{value}\textbf{);}

~

Feature Test Macro Requirements for glibc (see
\textbf{feature\_test\_macros}(7)): \\

~

\textbf{a64l}(), \textbf{l64a}():

~

\_SVID\_SOURCE \textbar{}\textbar{} \_XOPEN\_SOURCE~\textgreater{}=~500
\textbar{}\textbar{} \_XOPEN\_SOURCE~\&\&~\_XOPEN\_SOURCE\_EXTENDED

\hyperdef{}{DESCRIPTION}{\section{\hyperref[DESCRIPTION]{DESCRIPTION}}\label{DESCRIPTION}}

These functions provide a conversion between 32-bit long integers and
little-endian base-64 ASCII strings (of length zero to six). If the
string used as argument for \textbf{a64l}() has length greater than six,
only the first six bytes are used. If the type \emph{long} has more than
32 bits, then \textbf{l64a}() uses only the low order 32 bits of
\emph{value}, and \textbf{a64l}() sign-extends its 32-bit result.

The 64 digits in the base-64 system are:

\begin{verbatim}

'.' represents a 0
'/' represents a 1
0-9 represent  2-11
A-Z represent 12-37
a-z represent 38-63
\end{verbatim}

So 123 = 59*64\^{}0 + 1*64\^{}1 = ``v/''.

\hyperdef{}{ATTRIBUTES}{\section{\hyperref[ATTRIBUTES]{ATTRIBUTES}}\label{ATTRIBUTES}}

\hyperdef{}{Multithreadingux5fux28seeux5fpthreadsux287ux29ux29}{\subsection{\hyperref[Multithreadingux5fux28seeux5fpthreadsux287ux29ux29]{Multithreading
(see
pthreads(7))}}\label{Multithreadingux5fux28seeux5fpthreadsux287ux29ux29}}

The \textbf{l64a}() function is not thread-safe.

The \textbf{a64l}() function is thread-safe.

\hyperdef{}{CONFORMINGux5fTO}{\section{\hyperref[CONFORMINGux5fTO]{CONFORMING
TO}}\label{CONFORMINGux5fTO}}

POSIX.1-2001.

\hyperdef{}{NOTES}{\section{\hyperref[NOTES]{NOTES}}\label{NOTES}}

The value returned by \textbf{l64a}() may be a pointer to a static
buffer, possibly overwritten by later calls.

The behavior of \textbf{l64a}() is undefined when \emph{value} is
negative. If \emph{value} is zero, it returns an empty string.

These functions are broken in glibc before 2.2.5 (puts most significant
digit first).

This is not the encoding used by \textbf{uuencode}(1).

\hyperdef{}{SEEux5fALSO}{\section{\hyperref[SEEux5fALSO]{SEE
ALSO}}\label{SEEux5fALSO}}

\textbf{uuencode}(1), \textbf{strtoul}(3)

\hyperdef{}{COLOPHON}{\section{\hyperref[COLOPHON]{COLOPHON}}\label{COLOPHON}}

This page is part of release 3.54 of the Linux \emph{man-pages} project.
A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.

\begin{longtable}[c]{@{}ll@{}}
\toprule\addlinespace
2013-06-21 &
\\\addlinespace
\bottomrule
\end{longtable}
\end{document}

EDITAR

Como nenhuma resposta se encaixa perfeitamente para o requisito, fiz uma alteração na minha pergunta. A mudança também me dá o mesmo resultado, mas de maneira diferente.

Principalmente, quero vincular todo o texto em negrito ao título da mesma palavra.
por exemplo Onde eu chegar \textbf{malloc}eu quero fazer um link com \title{MALLOC(3)}e \textbf{a64l}para \title{A64L(3)}.

Agora, crio um arquivo indexque contém a palavra do título. índice de
arquivo

MALLOC(3)
A64L(3)  

ou

 MALLOC
 A64L

ou

 malloc
 a64l

Acho que usar o indexarquivo modificando o arquivo principal é mais fácil do que o modo anterior.
pseudo-código

while read word
do
l_word=${word,,}
echo $l_word
sed -e 's/\\title{$word\(3\)}/\\title{\\hypertarget{$word}{$word\(3\)}}/' -e 's/\\textbf{$l_word}/\\textbf{\\hyperlink{$word}{$l_word}}/' inputfile > output.tex
done < index

[Existem alguns erros neste código, que não podem ser detectados por mim]

awk text-processing
  • 2 2 respostas
  • 243 Views

2 respostas

  • Voted
  1. Praveen Kumar BS
    2017-12-29T20:56:23+08:002017-12-29T20:56:23+08:00

    Acho que abaixo um funciona gentilmente, verifique e atualize. Como testado para alguns dados, funcionou para mim

    sed "/title/s/{.*/{\hypertarget{&&/g" filename | sed -e "/title/s/A64/a64/1" -e "/title/s/MALLOC/malloc/1" | sed "/textbf/s/{.*}/{\hyperlink&&/g"| sed "s/{\{2\}/{/1"  | sed "s/(3)//1"
    
    • 1
  2. Best Answer
    alhelal
    2017-12-30T08:21:55+08:002017-12-30T08:21:55+08:00
    #!/bin/bash
    while read word
    do
    l_word=${word,,}
    sed -e s/\\\\title{$word\(3\)}/\\\\title{\\\\hypertarget{$word}{$word\(3\)}}/g -e s/\\\\textbf{$l_word}/\\\\textbf{\\\\hyperlink{$word}{$l_word}}/g inputfile > output.tex
    done < index  
    

    Embora isso funcione, pode ser feito sem o arquivo de índice que é regex que não posso criar.

    • 0

relate perguntas

  • Reorganize as letras e compare duas palavras

  • Subtraindo a mesma coluna entre duas linhas no awk

  • Embaralhamento de arquivo de várias linhas

  • como posso alterar o caso do caractere (de baixo para cima e vice-versa)? ao mesmo tempo [duplicado]

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Matriz JSON para bash variáveis ​​usando jq

    • 4 respostas
  • Marko Smith

    A data pode formatar a hora atual para o fuso horário GMT? [duplicado]

    • 2 respostas
  • Marko Smith

    bash + lê variáveis ​​e valores do arquivo pelo script bash

    • 4 respostas
  • Marko Smith

    Como posso copiar um diretório e renomeá-lo no mesmo comando?

    • 4 respostas
  • Marko Smith

    conexão ssh. Conexão X11 rejeitada devido a autenticação incorreta

    • 3 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Marko Smith

    comando systemctl não funciona no RHEL 6

    • 3 respostas
  • Marko Smith

    rsync porta 22 e 873 uso

    • 2 respostas
  • Marko Smith

    snap /dev/loop em 100% de utilização -- sem espaço livre

    • 1 respostas
  • Marko Smith

    chave de impressão jq e valor para todos no subobjeto

    • 2 respostas
  • Martin Hope
    EHerman Matriz JSON para bash variáveis ​​usando jq 2017-12-31 14:50:58 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Drux A data pode formatar a hora atual para o fuso horário GMT? [duplicado] 2017-12-26 11:35:07 +0800 CST
  • Martin Hope
    AllisonC Como posso copiar um diretório e renomeá-lo no mesmo comando? 2017-12-22 05:28:06 +0800 CST
  • Martin Hope
    Steve Como as permissões de arquivo funcionam para o usuário "root"? 2017-12-22 02:46:01 +0800 CST
  • Martin Hope
    Bagas Sanjaya Por que o Linux usa LF como caractere de nova linha? 2017-12-20 05:48:21 +0800 CST
  • Martin Hope
    Cbhihe Altere o editor padrão para vim para _ sudo systemctl edit [unit-file] _ 2017-12-03 10:11:38 +0800 CST
  • Martin Hope
    showkey Como baixar o pacote não instalá-lo com o comando apt-get? 2017-12-03 02:15:02 +0800 CST
  • Martin Hope
    youxiao Por que os diretórios /home, /usr, /var, etc. têm o mesmo número de inode (2)? 2017-12-02 05:33:41 +0800 CST
  • Martin Hope
    user223600 gpg — o comando list-keys gera uid [ desconhecido ] depois de importar a chave privada para uma instalação limpa 2017-11-26 18:26:02 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve