Re: Conversion of text in shell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Fri, October 12, 2007 4:54 pm, roland hellström wrote:
>
> Hi! I want to convert the lines
> 1.1,3.19e-4
> 1.2,3.05e-3
> 10.5,9.14e8
> (as example)
>
> to
>
> 1,1 & $3,19 \cdot 10^{-4}$\\
> etc.. from one file and save these in a new file
> Rly lost here except I know I should use regexp and MAYBE sed somehow :)
> Thx for any help

Assuming that you have those lines in a file called numbers.txt, you can
execute the following (all on one line):

cat numbers.txt | tr '.,e' ',^^' | awk -F^ '{printf("%s & $%s \\cdot
10^{%s}$\\\\\n", $1, $2, $3);}'

The output will be:

1,1 & $3,19 \cdot 10^{-4}$\\
1,2 & $3,05 \cdot 10^{-3}$\\
10,5 & $9,14 \cdot 10^{8}$\\

Not the most elegant solution, but it works.  I hope this is what you were
looking for.
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux