Download your favorite Linux distribution at LQ ISO.
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, 01:31 AM   #1
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 593

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, 01:34 AM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

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

Original Poster
Rep: Reputation: 30
Thanks a lot

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

Rep: Reputation: 235Reputation: 235Reputation: 235
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 07:16 PM
Cut Help metallica1973 Programming 67 12-20-2007 04:36 PM
how to cut an image ? hectorDUQUE Fedora 1 04-28-2007 09:35 PM
Ls and cut problem Phiebie Debian 2 07-14-2005 07:10 AM
How can I cut something between quotes? jfall Linux - General 2 02-09-2005 09:03 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:19 AM.

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