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
Reattemps Calculation using awk zanetti321 UNIX for Advanced & Expert Users 0 04-16-2008 03:13 AM
AWK equation evaluation. srdgeo Shell Programming and Scripting 3 11-23-2007 09:10 AM
MD5 hash calculation zedex High Level Programming 4 02-23-2007 11:37 PM
awk calculation kekanap Shell Programming and Scripting 4 11-17-2006 04:39 AM
time calculation liux99 UNIX for Advanced & Expert Users 2 08-18-2005 07:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-16-2006
Registered User
 

Join Date: Nov 2006
Posts: 2
equation calculation on Unix

Hay, guys,
Any ideas how to calculate like this:
in first file, there're number of lines listing 2+3, 6*9 .......
Then, how to get the result and put them in another file in format:

2+3 5
6*9 54

......

sheerly by shell command, no scripts required.
Reply With Quote
Forum Sponsor
  #2  
Old 11-16-2006
justsam's Avatar
Registered User
 

Join Date: Oct 2006
Location: Bangalore,India
Posts: 37
sed 's/\*/\\\*/' file1 > dummy
sed 's/\//\\\//' dummy > file2
while read line
do
echo "$line \c" >> Output
echo "$line" | bc >> Output
done < file2
Reply With Quote
  #3  
Old 11-16-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
#!/bin/ksh

while read line
do
  echo "${line} $(echo ${line} | bc)"
done < myFile.txt
Reply With Quote
  #4  
Old 11-16-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
The way the question is phrased I tend to think that we may have homework rule violation here.
But:
bc < input > temp ; paste input temp > output ; rm temp
Reply With Quote
  #5  
Old 11-16-2006
Registered User
 

Join Date: Nov 2006
Posts: 2
Thumbs up Thank you all

Thanks Perderabo,
I think you answer is fairly enough. vgersh99&justsam's genius work is also appreciated.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:22 AM.


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

Content Relevant URLs by vBSEO 3.2.0