The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file command rprajendran UNIX for Advanced & Expert Users 3 05-13-2008 10:45 AM
rm command not able to remove file jambesh Shell Programming and Scripting 7 12-21-2007 03:37 AM
What is the command to add heading to a file? whatisthis UNIX for Dummies Questions & Answers 3 12-01-2005 11:17 PM
End of file using more command Enda Martin UNIX for Dummies Questions & Answers 3 06-18-2001 07:49 AM
for file in ???? - command tamer UNIX for Dummies Questions & Answers 10 01-31-2001 05:40 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 6
VI command for File Please

I have a file with numbers like:

2235900
2234500
2220000
22300
235700
2200
0

and I need a search and replace to
change the number to a 3 place decimal...
like this :

2235.900
2234.500
2220.000
22.300
235.700
2.200
.000

Can someone please help me with the command
I need to use in the VI editor to get these results
of a file that has 3724 lines of numbers I need
to make into 3 place decimal numbers?

Thanks so much.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-31-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
I dont think you can do this in VI. Unless someone who knows vi macros can knock something together .... if you only have 1 number per line and you dont mind 0.000 instead of .000 then the following will work:

perl -e 'while($line=<>) { printf ("%.3f\n",($line/1000));}' inputfile.txt > outputfile.txt

Or if you had multiple numbers on each line then maybe:

perl -e 'while($line=<>){$line =~ s{(\d+)}{sprintf("%.3f",$1/1000)}eg; print "$line";}' inputfile.txt > outputfile.txt

Last edited by vgersh99; 08-31-2005 at 01:26 PM.
Reply With Quote
  #3 (permalink)  
Old 08-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 6
Quote:
Originally Posted by Unbeliever
if you only have 1 number per line and you dont mind 0.000 instead of .000 then the following will work:
Unbeliever, Thanks for the reply. I will need to
get Perl loaded and give this a try.... running
windoz ... would really like to get back to the REAL OS but have too many apps that only run under windoz ....

Thanks,
Reply With Quote
  #4 (permalink)  
Old 08-31-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Code:
sed -e 's/\(.*\)\([0-9]\{3\}\)/\1.\2/;ta' -e 's/\(.*\)\([0-9]\{2\}\)/\1.0\2/;ta' -e 's/\(.*\)\([0-9]\{1\}\)/\1.00\2/;ta' -e ':a' fileName
Reply With Quote
  #5 (permalink)  
Old 08-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 6
Quote:
Originally Posted by Unbeliever
...
perl -e 'while($line=<>) { printf ("%.3f\n",($line/1000));}' inputfile.txt > outputfile.txt ...
Unbeliever, I am getting a
" > was unexpected at this time. " when I try this command at a command prompt.

Any suggestions?
Reply With Quote
  #6 (permalink)  
Old 08-31-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,355
Unbeliever's code works perfectly for me. *shrug*
Reply With Quote
  #7 (permalink)  
Old 08-31-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Quote:
Originally Posted by Perderabo
Unbeliever's code works perfectly for me. *shrug*
... although his SECOND sample has a missing single-quote....
lemme add it in.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0