Register
It is currently Wed Jul 30, 2014 9:21 pm

Reading from a text file and outputting


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Mar 11, 2011 4:18 am   

Joined: Fri Mar 11, 2011 4:14 am
Posts: 1
Hello,

Firstly i'd like to introduce myself before I ask my question, i am currently studying a "Network Operating System 2" course, and in the syllabus the professor decided to use Ubuntu Linux for us.

This is a first for me and I am truly greatly interested in the OS. It seems like a solid system once you get to know the deep foundations of it.

The professor has already given us an assignment, but I feel its not fair as its just a bit too much from out of what he taught us .. He did not teach us what he is asking for.

He asked us to create to a text file which lists the Sales from two Salespersons, and each one will have an amount for each month .. So 12 entries for each salesperson.

Using that text file, we should write a bash script which would read the values from the above text file, and produce a "Monthly Sales" text file, which shows the total sales of each month (combined from both the salespersons)..

I would like to ask for some guidance, some help on how to start. It's just that he didn't teach us any commands about this matter..

Thank you so much for reading !

I have formatted the text file as follows:

Code:
Salesman 1
100
200
300
400
500
600
700
800
900
1000
1100
1200

Salesman 2
1200
1100
1000
900
800
700
600
500
400
300
200
100


Top
 Profile  
 PostPosted: Fri Mar 11, 2011 2:00 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
I would suggest reformatting the file with data like so:
Code:
Salesman1 Salesman2
1200 100
1100 200
1000 300
...   ...

then with a 'while read value1 value2' loop, you can parse all the lines and thus the data.


Top
 Profile  
 PostPosted: Fri Mar 25, 2011 2:29 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
E.g. like this:
Code:
paste 1333.1 1333.2  | grep -v S | sed 's/\t/+/' | bc


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP