1

I'm trying to do some formatting to some man pages and I need to add

] hfill \\

to certain headers. I want to make this

NAME
   env - run a program in a modified environment

SYNOPSIS
   env    [-]    [-i]    [-u   name]   [--ignore-environment]
   [--unset=name] [name=value]... [command [args...]]

DESCRIPTION
   This manual page documents the GNU version  of  env.   env
   runs  a  command with an environment modified as specified
   by the command line...

into this

\item[NAME] \hfill \\
   env - run a program in a modified environment

\item[SYNOPSIS] \hfill \\
   env    [-]    [-i]    [-u   name]   [-\hspace{.01cm}-ignore-environment]
   [-\hspace{.01cm}-unset=name] [name=value]... [command [args...]]

\item[DESCRIPTION] \hfill \\
   This manual page documents the GNU version  of  env.   env
   runs  a  command with an environment modified as specified
   by the command line...

I got the "\item[" part down but I can't get the other half for whatever reasons. The command I'm using:

 /[A-Z]/s/$/\] \\hfill \\\\/

works but shows up on lines I don't want.

1
  • The regex /[A-Z]/ matches any line with a capital letter. Did you want it to be /^\\item\[[A-Z]/ so that it only matches a capital letter that follows \item[ Commented Sep 17, 2015 at 6:04

3 Answers 3

1

Try this, assuming header ar only line starting with a capital letter

sed '/^[A-Z]/ s/.*/\\item[&] \\hfill \\\\/' YourFile

for the \hspace{.01cm}, you shold define when it should occur (condition for)

Sign up to request clarification or add additional context in comments.

Comments

0

This might work for you (GNU sed):

sed 's/^[[:upper:]]\+$/\\item[&] \\hfill \\\\/;s/\[--/[-\\hspace{.01cm}-/g' file

If you do not have GNU sed, try:

sed -e 's/^[[:upper:]][[:upper:]]*$/\\item[&] \\hfill \\\\/' -e 's/\[--/[-\\hspace{.01cm}-/g' file

Comments

0
sed -r 's/^([A-Z]+)$/\\item[\1] \\hfill \\\\/' file.txt

you can do it by one step.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.