Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-09-2013, 04:25 AM   #1
LQ Newbie
Registered: Jul 2013
Location: Montenegro
Posts: 3

Rep: Reputation: Disabled
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?
Old 07-09-2013, 04:45 AM   #2
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

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

Last edited by mddnix; 07-09-2013 at 04:48 AM.
1 members found this post helpful.
Old 07-09-2013, 04:48 AM   #3
LQ Newbie
Registered: Jul 2013
Location: Montenegro
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you very much! It works.

Edit: I know that switches, thanks...

Last edited by Xilonen; 07-09-2013 at 06:12 AM.


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
[SOLVED] Shell script to remove selected line number from text file. ChocaMocha Programming 4 04-25-2013 03:11 PM
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 12:29 PM
How do I extract a file on the command line Felixone Linux - Newbie 5 10-01-2008 10:14 AM
highlight text of a file from specified line number tanveer Linux - General 9 12-06-2006 10:27 PM
"how do I extract a number from a text file using shell command?" sdandeker Linux - Networking 3 02-12-2004 08:54 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:14 AM.

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