LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-17-2011, 12:48 AM   #1
athrin
Member
 
Registered: Mar 2011
Posts: 135

Rep: Reputation: 1
using cut


i want to cut
MemTotal: 254788 kB
into
254788
can someone help me with that
 
Old 03-17-2011, 12:50 AM   #2
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
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.
Old 03-17-2011, 12:56 AM   #3
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
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.
Old 03-17-2011, 12:57 AM   #4
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
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
 
Old 03-17-2011, 12:58 AM   #5
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Quote:
Originally Posted by Telengard View Post
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.
 
Old 03-17-2011, 01:11 AM   #6
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by athrin View Post
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 View Post
I didn't know that, thanks.
You're welcome of course.

Last edited by Telengard; 03-17-2011 at 01:12 AM.
 
Old 03-17-2011, 01:13 AM   #7
athrin
Member
 
Registered: Mar 2011
Posts: 135

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Telengard View Post
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
 
Old 03-17-2011, 01:18 AM   #8
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by athrin View Post
thanks for your help
You're very welcome. I'm just glad to know you found my response helpful.
 
  


Reply

Tags
awk, command line, cut, memory


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
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 08:55 PM
How to use Cut ZAMO Linux - General 3 09-25-2008 11:39 AM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 07:16 PM
Cut Help metallica1973 Programming 67 12-20-2007 04:36 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration