|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I'm not sure how to go about this in the most effective way, but I'd
thought I'd just throw it out there and see what everyone might come up with: The input file is something like this (a fixed size ASCII table: ESC x x x Description ESC y y (A) Description2 ESC z (V) Description3 Px = 4 Description5 7 (V) Description6 9 (A) Description7 I'd like to have it come out like this (a LaTeX-formatted table entry): \verb=ESC x x x= & & Description \\ \hline \verb=ESC y y= & (A) & Description2 \\ \hline \verb=ESC z= & (V) & Description3 \\ Px = 4 Description5 7 (V) Description6 9 (A) Description7 ....the last few lines will eventually be converted into a "table-within-a-table". First stab with sed, I would think: sed '/^ESC/{ s/ *\([VA]\) */ \& \1 \& /; s/ */ \& \& /; s/$/ \\\\ \\hline/; }' ....or did I just solve it? ;-) Bigger challenge: make it come out: \verb=ESC x x x= & & Description \\ \hline \verb=ESC y y= & (A) & Description2 \\ \hline \verb=ESC z= & (V) & Description3 \\ \center \begin{tabular}{r|c|l} Px = 4 & & Description5 \\ 7 & (V) & Description6 \\ 9 & (A) & Description7 \\ \end{tabular} \end{center} \\ I'm not sure how to make the begin and end (with sed), but since this is within vi, I can just use a macro to insert them, and do this: sed '/^ESC/{ s/ *\([VA]\) */ \& \1 \& /; s/ */ \& \& /; s/$/ \\\\ \\hline/; }; /^ /{ s/^ *//; s/ *\([VA]\) */ \& \1 \& /; s/ */ \& \& /; s/$/ \\\\/; }' Thoughts? By the way, I know sed a *whole* lot more than LaTeX - so thoughts on the LaTeX are also welcome... Thanks! Too bad there's not a comp.lang.sed ;-) Also, it would seem I can't just use that as given within vim as input to a !,G command; I'll have to do something else - probably act on a file and copy it back in... |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
David Douthitt wrote:
> I'm not sure how to go about this in the most effective way, but I'd > thought I'd just throw it out there and see what everyone might come up > with: > > The input file is something like this (a fixed size ASCII table: > > ESC x x x Description > ESC y y (A) Description2 > ESC z (V) Description3 > Px = 4 Description5 > 7 (V) Description6 > 9 (A) Description7 > <snip> > ...or did I just solve it? ;-) Bigger challenge: make it come out: > > \verb=ESC x x x= & & Description \\ \hline > \verb=ESC y y= & (A) & Description2 \\ \hline > \verb=ESC z= & (V) & Description3 \\ > \center > \begin{tabular}{r|c|l} > Px = 4 & & Description5 \\ > 7 & (V) & Description6 \\ > 9 & (A) & Description7 \\ > \end{tabular} > \end{center} \\ <snip> > Thanks! Too bad there's not a comp.lang.sed ;-) But there is a comp.lang.awk and awk's probably a more appropriate tool to use to solve this problem. You don't explain what information you're keying off to make the conversions so this may not be how you need it to work, but this will produce the output you want for the given input: $ cat file ESC x x x Description ESC y y (A) Description2 ESC z (V) Description3 Px = 4 Description5 7 (V) Description6 9 (A) Description7 $ awk -f tst.awk file \verb=ESC x x x= & & Description \\ \hline \verb=ESC y y= & (A) & Description2 \\ \hline \verb=ESC z= & (V) & Description3 \\ \center \begin{tabular}{r|c|l} Px = 4 & & Description5 \\ 7 & (V) & Description6 \\ 9 & (A) & Description7 \\ \end{tabular} \end{center} \\ $ cat tst.awk FNR==1 { printf "\\verb=%s %s %s %s= & & %s \\\\ \\hline\n",$1,$2,$3,$4,$5} FNR==2 { printf "\\verb=%s %s %s= & %s & %s \\\\ \\hline\n",$1,$2,$3,$4,$5} FNR==3 { printf "\\verb=%s %s= & %s & %s \\\\\n",$1,$2,$3,$4} FNR==4 { printf "\\center\n" printf "\\begin{tabular}{r|c|l}\n" printf "%s %s %s & & %s \\\\\n",$1,$2,$3,$4 } FNR==5 { printf "%s & %s & %s \\\\\n",$1,$2,$3 } FNR==6 { printf "%s & %s & %s \\\\\n",$1,$2,$3 printf "\\end{tabular}\n" printf "\\end{center} \\\\\n" } Regards, Ed. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
David Douthitt wrote:
> I'm not sure how to go about this in the most effective way, but I'd > thought I'd just throw it out there and see what everyone might come up > with: > > The input file is something like this (a fixed size ASCII table: > > ESC x x x Description > ESC y y (A) Description2 > ESC z (V) Description3 > Px = 4 Description5 > 7 (V) Description6 > 9 (A) Description7 > > I'd like to have it come out like this (a LaTeX-formatted table entry): > > \verb=ESC x x x= & & Description \\ \hline > \verb=ESC y y= & (A) & Description2 \\ \hline > \verb=ESC z= & (V) & Description3 \\ > Px = 4 Description5 > 7 (V) Description6 > 9 (A) Description7 $ echo "ESC x x x Description ESC y y (A) Description2 ESC z (V) Description3 Px = 4 Description5 7 (V) Description6 9 (A) Description7" | \ perl -lpe' /^ESC/ and $_ = sprintf q[\verb=%s= & %s & %s \\\%s], unpack( q[A15 A6 A*], $_ ), /\(V\)/ ? q[] : q[ \hline] ' \verb=ESC x x x= & & Description \\ \hline \verb=ESC y y= & (A) & Description2 \\ \hline \verb=ESC z= & (V) & Description3 \\ Px = 4 Description5 7 (V) Description6 9 (A) Description7 John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall |
|
![]() |
| Outils de la discussion | |
|
|