LinuxQuestions.org
Review your favorite Linux distribution.
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 12-24-2009, 11:02 AM   #1
jnojr
Member
 
Registered: Sep 2007
Location: San Diego, CA
Posts: 222

Rep: Reputation: 20
Problem with cut


I want to perform an action when swap is being used too heavily. My first thought was to use free, grep for "Swap:", and cut the column that shows how much is being used. But that just isn't happening.

The man page for cut says that TAB is the default delimiter, but:

Quote:
[jnojr@netcentric ~]$ free | grep Swap | cut -f4
Swap: 8388600 3198076 5190524
I tried adding the tab character specifically a couple of ways:

Quote:
[jnojr@netcentric ~]$ free | grep Swap | cut -d'' -f4
cut: the delimiter must be a single character
Try `cut --help' for more information.
(That was single-quote, TAB, single-quote)

Quote:
[jnojr@netcentric ~]$ free | grep Swap | cut -d$'\t' -f4
Swap: 8388600 3193524 5195076
I suppose it's possible that free isn't using a tab character to format the output, but that doesn't make a lot of sense to me.
 
Old 12-24-2009, 11:16 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by jnojr View Post
I suppose it's possible that free isn't using a tab character to format the output, but that doesn't make a lot of sense to me.
free doesn't use tabs. I just confirmed it by free > free.out and examining the output file in vim.

It's a rational design choice because there is no way to know what the tab setting is on all possible output "media". I think it's the same for most commands.
 
Old 12-24-2009, 11:39 AM   #3
jnojr
Member
 
Registered: Sep 2007
Location: San Diego, CA
Posts: 222

Original Poster
Rep: Reputation: 20
Criminy.

Well, since cut doesn't have a setting to consider "any/all whitespace" as a delimiter, and there's no way to know in advance how many spaces it'll use...
 
Old 12-24-2009, 11:59 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Not easily but you could use a tool that regards multiple spaces as a single field separator such as awk or the shell itself.
Code:
array=( $(free) )
echo "Swap used is ${array[19]}"
 
Old 12-24-2009, 01:27 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Just hitting tab on the command line generally wont work because your shell will grab it and try interpret it as a completion request. You can enter literal characters on the command line by first typing Ctrl-V.

HTH,

Evo2.

PS. In regard to your actual question ,I'm pretty sure that the output of free is just padded with multiple spaces.

Last edited by evo2; 12-24-2009 at 01:29 PM.
 
  


Reply


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 command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 07:16 PM
Cut command Problem ratul_11 Linux - Newbie 3 10-11-2007 03:02 AM
Ls and cut problem Phiebie Debian 2 07-14-2005 07:10 AM
cut-problem dahljor Programming 2 07-08-2003 12:58 PM

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

All times are GMT -5. The time now is 05:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration