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 07-09-2013, 05:25 AM   #1
Xilonen
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, 05:45 AM   #2
mddnix
Member
 
Registered: Mar 2013
Location: Bengaluru, India
Distribution: Redhat, Arch, Ubuntu
Posts: 498

Rep: Reputation: 137Reputation: 137
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}'

Last edited by mddnix; 07-09-2013 at 05:48 AM.
 
1 members found this post helpful.
Old 07-09-2013, 05:48 AM   #3
Xilonen
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 07:12 AM.
 
  


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


All times are GMT -5. The time now is 08:58 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