LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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: 148Reputation: 148
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
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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: 148Reputation: 148
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: 148Reputation: 148
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:37 AM.

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
Open Source Consulting | Domain Registration