[CentOS] Conversion of text in shell

Ross S. W. Walker rwalker at medallion.com
Fri Oct 12 21:57:54 UTC 2007

roland hellström wrote:
> Indeed this is a chalmers student. The purpose of asking 
> though is to learn it, because I find it very hard to learn 
> without seeing an example of it.
> Thx for the reply it seemed to work well :) Although it would 
> be interesting to see if this could be done with the sed 
> command somehow?
> Thx in advance

Then let me help you think it out:

Given a text file with this data:
10.5,9.14e-8 <- I'm guessing this was suppose to be scientific not

Convert to a text file:
1,1 & $3,19 \cdot 10^{-4}$\\
1,2 & $3,05 \cdot 10^{-3}$\\
10,5 & $9,14 \cdot 10^{-8}$\\

Look for the pattern match ups:
1,1 & $3,19 \cdot 10^{-4}$\\

1,2 & $3,05 \cdot 10^{-3}$\\

10,5 & $9,14 \cdot 10^{-8}$\\

It looks like:
1) decimals converted to commas
2) commas converted to " & "
3) "e" converted to " \cdot 10^{<>}$\\"
4) <> substituted for whatever comes after the "e"

Now if you convert decimals to commas BEFORE you convert
commas to " & " then you will have garbage, so you need
to convert commas to " & " first, then decimals to
commas, then apply the conversion w/ substituion.

Substitution is handled with the \(\) operator like such:

echo "this is a test" | sed -e 's/\(.*\) is a \(.*\)/\2 is NOT a \1/'

Will output: "test is NOT a this"

Can be done in 3 steps, sed can take multiple operations
if you separate them with ;

<snip mangled thread>

PS Fix your mail client to post in plain text and put
your reply text at the bottom of the email instead of
the top.

This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.

More information about the CentOS mailing list