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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-17-2011, 12:48 AM
|
#1
|
|
Member
Registered: Mar 2011
Posts: 135
Rep:
|
using cut
i want to cut
MemTotal: 254788 kB
into
254788
can someone help me with that
|
|
|
|
03-17-2011, 12:50 AM
|
#2
|
|
Guru
Registered: Apr 2005
Location: /dev/null
Distribution: technixOS
Posts: 5,723
|
Code:
echo "MemTotal: 254788 kB" | cut -c 11-16
That should do it. Replace whatever command need be in place of echo. Note: I am on windows right now at work, so you might have to edit the numbers to get the correct output.
Cheers,
Josh
|
|
|
1 members found this post helpful.
|
03-17-2011, 12:56 AM
|
#3
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Rep: 
|
I would use
Code:
~$ echo 'MemTotal: 254788 kB' | cut -d ' ' -f 2
254788
~$
This way it works even if the length of the string changes.
|
|
|
1 members found this post helpful.
|
03-17-2011, 12:57 AM
|
#4
|
|
Member
Registered: Mar 2011
Posts: 135
Original Poster
Rep:
|
aaa.. i want to cut it without using echo.
if i use
cat /proc/meminfo | grep MemTotal | cut -d : -f2
254788 kB will shown and i also want to remove the kB
|
|
|
|
03-17-2011, 12:58 AM
|
#5
|
|
Guru
Registered: Apr 2005
Location: /dev/null
Distribution: technixOS
Posts: 5,723
|
Quote:
Originally Posted by Telengard
I would use
Code:
~$ echo 'MemTotal: 254788 kB' | cut -d ' ' -f 2
254788
~$
This way it works even if the length of the string changes.
|
I didn't know that, thanks.
|
|
|
|
03-17-2011, 01:11 AM
|
#6
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Rep: 
|
Quote:
Originally Posted by athrin
aaa.. i want to cut it without using echo.
if i use
cat /proc/meminfo | grep MemTotal | cut -d : -f2
254788 kB will shown and i also want to remove the kB
|
I see why. cut isn't very intelligent about field separators. Try this instead:
Code:
~$ cat /proc/meminfo | awk '/MemTotal/ {print $2}'
1033828
~$
Quote:
Originally Posted by corp769
I didn't know that, thanks.
|
You're welcome of course.
Last edited by Telengard; 03-17-2011 at 01:12 AM.
|
|
|
|
03-17-2011, 01:13 AM
|
#7
|
|
Member
Registered: Mar 2011
Posts: 135
Original Poster
Rep:
|
Quote:
Originally Posted by Telengard
I see why. cut isn't very intelligent about field separators. Try this instead:
Code:
~$ cat /proc/meminfo | awk '/MemTotal/ {print $2}'
1033828
~$
You're welcome of course.
|
thanks for your help
|
|
|
|
03-17-2011, 01:18 AM
|
#8
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Rep: 
|
Quote:
Originally Posted by athrin
thanks for your help
|
You're very welcome. I'm just glad to know you found my response helpful.

|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:59 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|