Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-25-2008, 02:31 AM   #1
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 584

Rep: Reputation: 30
How to use Cut

Hi all,

Am trying to cut the kilobytes(K) or Megabytes(M) from the following. But am unable to get the help from man page of cut.

ls -lht myfile |awk '{print $5}' |cut ???

Say if the file size 12M , then I want to truncate the "M" from it and need only 12.

Old 09-25-2008, 02:34 AM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 243Reputation: 243Reputation: 243
ls -lht 9115.THM | awk '{print $5+0}'
Old 09-25-2008, 03:13 AM   #3
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 584

Original Poster
Rep: Reputation: 30
Thanks a lot

Cheers to become the Senior Member Soon
Old 09-25-2008, 12:39 PM   #4
LQ Guru
Registered: Jan 2001
Posts: 24,147

Rep: Reputation: 229Reputation: 229Reputation: 229
cut is like awk but is only the basic portion of it. It only cuts or removes from each line in a file or output. In this case, you could have used cut to grab the size but cut can't eliminate the M, otherwords, it can't really manipulate the output in anyway.

Use cut if you don't need to manipulate the output, use awk if you do. That's how I approach these two commands.


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
Cut Help metallica1973 Programming 67 12-20-2007 05:36 PM
how to cut an image ? hectorDUQUE Fedora 1 04-28-2007 10:35 PM
Ls and cut problem Phiebie Debian 2 07-14-2005 08:10 AM
How can I cut something between quotes? jfall Linux - General 2 02-09-2005 10:03 PM

All times are GMT -5. The time now is 12:16 PM.

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