LinuxQuestions.org
Visit Jeremy's Blog.
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 02-03-2010, 04:05 PM   #1
buee
Member
 
Registered: May 2009
Posts: 81

Rep: Reputation: 16
Using awk to grab first number series


Hello, just wondering if this can be done as I'd like to use it in a script.

I want to take this:
Code:
root@ubox:~$ du /etc
80	/etc/laptop-mode/conf.d
4	/etc/laptop-mode/lm-ac-start
4	/etc/laptop-mode/lm-ac-stop
4	/etc/laptop-mode/nolm-ac-start
4	/etc/laptop-mode/batt-start
4	/etc/laptop-mode/nolm-ac-stop
124	/etc/laptop-mode
16	/etc/defoma/config
160	/etc/defoma/hints
204	/etc/defoma
8	/etc/firefox-3.5/pref
12	/etc/firefox-3.5/profile/chrome
48	/etc/firefox-3.5/profile
60	/etc/firefox-3.5
8	/etc/byobu
4	/etc/opt
68	/etc/speech-dispatcher/modules
12	/etc/speech-dispatcher/clients
96	/etc/speech-dispatcher
8	/etc/xulrunner-1.9.1
And just keep the file sizes at the very beginning, no spaces, no letters, nothing after the first series of numbers. Then I want to output those to a file to be added together later. I can handle the addition part, but awk confuses me

If it has any bearing, the endgame here is to create a script that will count files and file sizes, add them together on a daily basis to come up with a total. We have a NAS for computer backups and I would like to be able to look at one line of text and see how much data and file count we've backed up from today.
 
Old 02-03-2010, 04:08 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
If you want a total number for a specific directory like /etc...
Code:
du -s /etc
I would also suggest that you use rsync to do your backup and you can get a summary from it along with any problems it encountered during the operation...

You could also use cut to grab just the numbers...

Code:
du /etc | cut -f1
But totaling that up is going to yield a lie because of the way du displays data.

Last edited by rweaver; 02-03-2010 at 04:15 PM.
 
  


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
How to grab one number from a row in a text but not another number Mike_V Programming 9 04-25-2009 04:57 AM
square root of number using sqrt and/or awk skuz_ball Programming 4 08-04-2008 04:18 AM
Counting number of occurance in awk program sarajevo Programming 2 11-01-2006 10:31 AM
Number series generator sniff Programming 8 08-23-2005 03:26 AM
Using sscanf to grab an unknown number of variables R00ts Programming 4 06-06-2005 05:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:38 AM.

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
Open Source Consulting | Domain Registration