LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using awk to grab first number series (https://www.linuxquestions.org/questions/linux-newbie-8/using-awk-to-grab-first-number-series-786777/)

buee 02-03-2010 04:05 PM

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.

rweaver 02-03-2010 04:08 PM

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.


All times are GMT -5. The time now is 07:08 AM.