replacing 1e+ with powers of ten


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing 1e+ with powers of ten
# 1  
Old 02-06-2012
replacing 1e+ with powers of ten

Dear all,

I am trying to write a script that modifies a file created with gnuplot.

If (the "if" is important, some files might not have them) in the (tex) file there are instances like


Code:
      \put(1342,704){\makebox(0,0)[r]{\strut{} 1e+31}}%
      \csname LTb\endcsname%
      \put(1342,1383){\makebox(0,0)[r]{\strut{} 1e+32}}%
      \csname LTb\endcsname%
      \put(1342,2061){\makebox(0,0)[r]{\strut{} 1e+33}}%
      \csname LTb\endcsname%
      \put(1342,2740){\makebox(0,0)[r]{\strut{} 1e+34}}%
      \csname LTb\endcsname%
      \put(1342,3418){\makebox(0,0)[r]{\strut{} 1e+35}}%
      \csname LTb\endcsname%
      \put(1342,4097){\makebox(0,0)[r]{\strut{} 1e+36}}%
      \csname LTb\endcsname%
      \put(1342,4775){\makebox(0,0)[r]{\strut{} 1e+37}}%
      \csname LTb\endcsname%
      \put(1474,484){\makebox(0,0){\strut{} 1e-08}}%
      \csname LTb\endcsname%
      \put(2073,484){\makebox(0,0){\strut{} 1e-07}}%
      \csname LTb\endcsname%
      \put(2673,484){\makebox(0,0){\strut{} 1e-06}}%
      \csname LTb\endcsname%
      \put(3272,484){\makebox(0,0){\strut{} 1e-05}}%
      \csname LTb\endcsname%
      \put(3872,484){\makebox(0,0){\strut{} 0.0001}}%
      \csname LTb\endcsname%
      \put(4471,484){\makebox(0,0){\strut{} 0.001}}%
      \csname LTb\endcsname%
      \put(5071,484){\makebox(0,0){\strut{} 0.01}}%
      \csname LTb\endcsname%
      \put(5670,484){\makebox(0,0){\strut{} 0.1}}%
      \csname LTb\endcsname%
      \put(6270,484){\makebox(0,0){\strut{} 1}}%

then replace them with

Code:
      \put(1342,704){\makebox(0,0)[r]{\strut{} $10^{31}$}}%
      \csname LTb\endcsname%
      \put(1342,1383){\makebox(0,0)[r]{\strut{} $10^{32}$}}%
      \csname LTb\endcsname%
      \put(1342,2061){\makebox(0,0)[r]{\strut{} $10^{33}$}}%
      \csname LTb\endcsname%
      \put(1342,2740){\makebox(0,0)[r]{\strut{} $10^{34}$}}%
      \csname LTb\endcsname%
      \put(1342,3418){\makebox(0,0)[r]{\strut{} $10^{35}$}}%
      \csname LTb\endcsname%
      \put(1342,4097){\makebox(0,0)[r]{\strut{} $10^{36}$}}%
      \csname LTb\endcsname%
      \put(1342,4775){\makebox(0,0)[r]{\strut{} $10^{37}$}}%
      \csname LTb\endcsname%
      \put(1474,484){\makebox(0,0){\strut{} $10^{-08}$}}%
      \csname LTb\endcsname%
      \put(2073,484){\makebox(0,0){\strut{} $10^{-07}$}}%
      \csname LTb\endcsname%
      \put(2673,484){\makebox(0,0){\strut{} $10^{-06}$}}%
      \csname LTb\endcsname%
      \put(3272,484){\makebox(0,0){\strut{} $10^{-05}$}}%
      \csname LTb\endcsname%
      \put(3872,484){\makebox(0,0){\strut{} 0.0001}}%
      \csname LTb\endcsname%
      \put(4471,484){\makebox(0,0){\strut{} 0.001}}%
      \csname LTb\endcsname%
      \put(5071,484){\makebox(0,0){\strut{} 0.01}}%
      \csname LTb\endcsname%
      \put(5670,484){\makebox(0,0){\strut{} 0.1}}%
      \csname LTb\endcsname%
      \put(6270,484){\makebox(0,0){\strut{} 1}}%



i.e.

all e in a line preceded by \strut{} ---> replace with 0

all + in a line preceded by \strut{} ---> replace with ^{ and close bracket

all - in a line preceded by \strut{} ---> add before ^{ and close bracket

and then wrap all instances of 10^{whatever} with dollars ---> $10^{whatever}$


Thanks....
# 2  
Old 02-06-2012
All what in a line? Smilie

It looks like all you want to do is replace 1e+31 with $10^31?

Are you sure that's right? $10 sounds like a variable, not a number, and x^y isn't the same as x * 10^y...
# 3  
Old 02-06-2012
Hi,

that's right

This is a file that will be fed to latex, so that mathematical expressions must be that way:

$10^{31}$

etc...
# 4  
Old 02-06-2012
Try a bit of sed:
Code:
sed 's/1e+\{0,1\}\(-\{0,1\}[0-9]*\)/$10^{\1}$/g' infile

# 5  
Old 02-07-2012
Thanks! That did it!

Now... is there a way to remove the leading zeroes?

I mean, transform all 09 08 07 into 9 8 7

That would be perfect

Thanks

---------- Post updated at 08:25 PM ---------- Previous update was at 08:31 AM ----------

Code:
sed 's/1e+\{0,1\}\(-\{0,1\}[0-9]*\)/$10^{\1}$/g' | sed 's/{-0\(.*\)/{-\1/' | sed 's/{0\(.*\)/{\1/'

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sequential numbering from 1 to ten

Hi I am in a bind, I need create a script that will rename files as they come into a folder with sequential numbering at the begining starting at 1 and proceeding to ten then starting at 1 again. Such as 1_filename.pdf, 2_filename.pdf, 3_filename.pdf, 4_filename.pdf, 5_filename.pdf, 6_filename.pdf,... (6 Replies)
Discussion started by: Paul Walker
6 Replies

2. Shell Programming and Scripting

execute the shell script per ten seconds

hi, everyone. My want to execute the shell script below per 10 seconds PID=`pgrep java` if then /home/java/java fi crontab wouldn't help me. some one can give me suggestions?thanks ---------- Post updated at 07:29 AM ---------- Previous update was at 07:26 AM ---------- ... (6 Replies)
Discussion started by: AKB48
6 Replies

3. Shell Programming and Scripting

Retry every ten seconds while lockfile present

Hi, I have written below check lockfile script but need some tweaking on it. If there is a lockfile from present, I need the script to retry every 10 seconds to see if the lockfile is still there. After 120 seconds it should send an email. In my current version, if the script encounters... (6 Replies)
Discussion started by: Meert
6 Replies

4. Shell Programming and Scripting

Display top ten directories by size

Hi, I am new to Unix. I want to display top 10 folders by size. I tried with du -ksl * | sort -nr | head -10 command .But I am getting the following error -bash: /usr/bin/du: Argument list too long Can some one help me. Thanks. (5 Replies)
Discussion started by: Satyak
5 Replies

5. UNIX for Dummies Questions & Answers

Removing last ten characters from a column

I have a file that looks like this: hsa-miR-517b-4373244 0 4.116 hsa-miR-886-5p-4395304 1.173 1.95 hsa-miR-551b-4380945 1.62 1.722 hsa-miR-886-3p-4395305 1.479 3.074 hsa-miR-125a-3p-4395310 1.246 2.697 hsa-miR-874-4395379 1.985 1.721 I want it too look like this: ... (9 Replies)
Discussion started by: e3r1ck_ETT
9 Replies

6. Solaris

Will I lose drivers while upgrading to ten?

I'm running Solaris 8 with a box I just got and it has a VGA connection. Will I lose the VGA driver while upgrading to 10? I don't have a Sun Monitor so if so I'll be screwed. Tia (0 Replies)
Discussion started by: PapaPark
0 Replies
Login or Register to Ask a Question