LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Which command can extract just number from a line or text file? (https://www.linuxquestions.org/questions/linux-newbie-8/which-command-can-extract-just-number-from-a-line-or-text-file-4175468972/)

Xilonen 07-09-2013 04:25 AM

Which command can extract just number from a line or text file?
 
Hi people,
I'm using du command:
du folder_name
and that gives me the result, for example:
8 folder_name
I wonder- how can I get just that 8 (that number) without the name of folder next to it?
(I want to do that because I want to assign that value to a variable in a script.)
Or if I write the result of command in a text file:
du folder_name > some_file, how can I get that number (in this case 8)from that file?

Madhu Desai 07-09-2013 04:45 AM

Code:

du folder_name | awk '{print $1}'
Edit:
You can also use -s for summary, and -h for human readable format (e.g., 1K 234M 2G)
Code:

du -sh folder_name | awk '{print $1}'

Xilonen 07-09-2013 04:48 AM

Thank you very much! It works.


Edit: I know that switches, thanks...


All times are GMT -5. The time now is 06:59 AM.