sorting and stuff
first, how do you sort lines of a file given that each line has a date of format
%d %b %Y second, how do you display a list of numbers in xxxx.xx and add their sum? thanks, peace |
Re: sorting and stuff
Quote:
Code:
#!/bin/bash |
Yes, its in bash.
No, the file does not only contain dates its in this format: "some name|some number|`date "+%b %d %Y"`" "another name|another number|another date of same format" . . . . etc |
Can you copy and paste a sample of the file? Are you wanting to sort by date? Also paste some of the numbers which you want to calculate.
|
Quote:
Code:
#!/bin/bash |
yep got it. thanks.
say the text file is: Book|120|23 Dec 2004 Tea|20.3|24 Dec 2003 watch|1015.50|1 Jan 2005 coffee|10.00|7 Nov 2001 How do you display the prices in this manner: Book 20.00 23 Dec 2004 Tea 20.30 24 Dec 2003 watch 1015.50 1 Jan 2005 coffee 10.00 7 Nov 2001 prices must be right-justified so that each digit are aligned to each other down to the last cent and output is another text file |
It would be easier to change the date format to
%Y%m%d 20041212 then it can easily be sorted. Is this possible, do you have control? for doing all these operations including the sum probably best use perl. billy |
ive already done the sort by date part.
what i need is to format the prices from the raw data into the output i said earlier. and i cant use perl because this is a homework hehe |
well, with Korn shell you can typeset -R -L
a variable, which justifies it when output. you do like, typeset -R10 var_name (e.g. 10 chars width) before using it. dunno if bash has it. billy |
e.g:
Code:
|
Quote:
Quote:
Why?
|
who are you to judge someone that he diditn learn anything. who cares if its a homework. im not asking you and just copying every code that yo write here. and by the way, its not a homework, its a project. and its just a boogerly size of a problem compared to the whole code. I just didnt know that there was a %s
option for date, thats all. so dont be too self-righteous. "abuse my willingness"... hahahaha |
Quote:
|
Firing off on those who spend their free time helping you is not the best idea. Especially at (as homey put it "bash wizards") like Hko.
I usually allow homework questions in my forum as long I see some effort on the posters behalf. Quote:
Next time try: A) not insulting our members that try to help you B) post a question like: what's wrong with this code... and it may stay open longer. closing thread |
All times are GMT -5. The time now is 05:43 PM. |