LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-08-2013, 09:07 AM   #1
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Rep: Reputation: 48
writing a script to calculate sum of all files


hi ,
I am writing a script to do above
So far , I have done

Code:
find . -type f -printf "%s\n" | tr '\n' '+' | sed 's/+$//g' | bc
I get
(standard_in) 1: parse error
 
Old 04-08-2013, 10:43 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,952

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by sumeet inani View Post
hi ,
I am writing a script to do above So far , I have done
Code:
find . -type f -printf "%s\n" | tr '\n' '+' | sed 's/+$//g' | bc
I get (standard_in) 1: parse error
You've been here for five years now, and keep posting for assistance with scripting. Why haven't you read/followed the scripting tutorials you've been pointed to MANY times yet??

A VERY brief Google search turns up lots, and reading man pages would help you too.
Code:
find . -type f -printf "%s\n" | awk '{ x += $1 } END { print "total bytes:" x }'
After five years, you should know basic shell-scrpting and how to look things up.
 
Old 04-08-2013, 11:21 AM   #3
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
That is harsh . Given , i have shown my effort .
I was hoping that someone will point out the reason for failure of my script.
Because the output I get (1234+3423+3421+1256) seems appropriate for binary calculator input.
 
Old 04-08-2013, 11:28 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Quote:
Originally Posted by sumeet inani View Post
That is harsh . Given , i have shown my effort .
I was hoping that someone will point out the reason for failure of my script.
Because the output I get (1234+3423+3421+1256) seems appropriate for binary calculator input.
You need a new line at the end.

Change your
Code:
sed 's/+$//g'
to
Code:
sed 's/+$/\n/g'
 
2 members found this post helpful.
Old 04-08-2013, 11:49 AM   #5
sumeet inani
Member
 
Registered: Oct 2008
Posts: 895
Blog Entries: 26

Original Poster
Rep: Reputation: 48
thanks suicidaleggroll .

That went well .
 
Old 04-08-2013, 12:49 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,952

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by sumeet inani View Post
That is harsh . Given , i have shown my effort.
You have shown one line, with no context. Please see SEVERAL of your other posts, where you say you don't know scripting. Again, you've been here five years, and have been directed to MANY scripting tutorials.
Quote:
I was hoping that someone will point out the reason for failure of my script. Because the output I get (1234+3423+3421+1256) seems appropriate for binary calculator input.
And did you see where I gave you the line that would do it? That's one solution, and reading the tutorials would help too. Suicidaleggroll's solution would have been mentioned in them, if you read them. And you first posted that you got "(standard_in) 1: parse error"...now you say you get a different result.

Sorry if you think it's 'harsh', but after five years, shouldn't such basic things be a bit obvious?
 
Old 04-09-2013, 05:11 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Two simplified versions of the OP command:

Code:
find . -type f -printf "%s+" | sed 's/+$/\n/g' | bc

tot=$( find . -type f -printf "%s+" )
echo "${tot%+}" | bc
 
1 members found this post helpful.
Old 04-09-2013, 07:46 PM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
du -h?

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum up value of columns in 4 files using shell script reach.sree@gmail.com Programming 6 06-07-2012 08:29 PM
Writing a script that compares two different files random0munky Linux - Newbie 9 07-26-2011 08:55 PM
Need help in writing a script to move old files... NYMets91587 Linux - Newbie 9 02-20-2009 06:43 AM
I need to calculate the sum of filesizes from a list of files paulBottomley Linux - Newbie 5 04-25-2008 01:19 PM
writing awk script files bigmark Linux - Software 1 10-19-2005 11:33 AM


All times are GMT -5. The time now is 05:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration