LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-19-2009, 07:54 AM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 50
How use CUT -d 'delimiter' is delimiter is a TAB?


How use CUT -d 'delimiter' is delimiter is a TAB?


Any ideas. Google is not helping much
Best regards
 
Old 04-19-2009, 07:56 AM   #2
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 50
[ SOLVED ]
Quote:
Originally Posted by frenchn00b View Post
How use CUT -d 'delimiter' is delimiter is a TAB?


Any ideas. Google is not helping much
Best regards

MAN CUT is better and cuter than google cut.

Code:
cat  myfile  | cut  -f1 -s
take the first string
Code:
cat  myfile  | cut  -f2 -s
take the second string


[ SOLVED ]
 
Old 04-19-2009, 10:18 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
Just for the next search user.
1) that solution correctly states that TAB is default delimiter for cut.
2) "cut -f1 -s myfile" works on its own, so cat invocation is redundant
3)
Code:
cut -f1 -d\<TAB>
and
Code:
cut -f1 -d"<TAB>"
are useful to know - just as examples of shell escaping
 
Old 04-19-2009, 11:19 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
you can also use awk.
 
Old 01-31-2010, 02:03 AM   #5
sr71919
LQ Newbie
 
Registered: Dec 2009
Location: Chennai, Tamil nadu, INDIA
Distribution: Fedora
Posts: 14

Rep: Reputation: 1
press "<CTR> v" then the "<TAB>" key

cut -d "<CTR>v <TAB>"
 
Old 02-01-2010, 06:26 PM   #6
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by sr71919 View Post
press "<CTR> v" then the "<TAB>" key

cut -d "<CTR>v <TAB>"

Oh thanks that a cool trick too.
By the way if one type :
Code:
 ps aux  | cut  -f1 -s
it doesnt output
 
Old 02-01-2010, 09:07 PM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 111Reputation: 111
That's because word splitting makes the tab just ordinary whitespace to delimit parameters with. If you're really using Bash and not POSIX sh, then use $'\t' and Parameter Expansions. Or even play with IFS and use read:
Code:
IFS="." read h1 h2 h3 h4 <<< "127.0.0.1"
 
Old 02-01-2010, 09:25 PM   #8
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Depending on the input format, sometimes using "tr -s ' '" will sqeeze extra spaces to a single space letting cut or awk work properly with a space as the delimiter.

example:

ls -l | tr -s ' ' | cut -d' ' -f1,8-
 
Old 03-30-2010, 07:25 AM   #9
sabata.descordada
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
I use the awk

grep "833" session_20100321.log | awk '{ FS = "\t" ; printf(" %s %s\n", $5,$6); }'
 
Old 03-30-2010, 08:44 AM   #10
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,473

Rep: Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888
If your looking to use with ps then:

Code:
ps aux | awk '{ print $1}'
works
 
Old 10-08-2013, 01:49 AM   #11
m3n78am
LQ Newbie
 
Registered: Dec 2012
Posts: 1

Rep: Reputation: Disabled
use this

cut -d$'\t'
 
Old 10-08-2013, 03:00 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,676

Rep: Reputation: 487Reputation: 487Reputation: 487Reputation: 487Reputation: 487
When not in bash, use printf:

Code:
TAB=$(printf '\t')
echo "here  is a $TAB" | od -tx1
 
Old 11-06-2013, 03:17 AM   #13
sergani
LQ Newbie
 
Registered: Jan 2010
Distribution: Fedora, CentOS, OpenSuse, Oracle Enterprise Linux, MacOSX
Posts: 27

Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
If your looking to use with ps then:

Code:
ps aux | awk '{ print $1}'
works
Thanks man, don't know why AWK slips my mind always!
 
  


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
Need 'cut' with mulit char delimiter endfx Programming 5 03-04-2009 01:37 AM
sed : how to use delimiter Ashok_mittal Linux - Newbie 2 12-17-2008 06:41 AM
xls2csv delimiter waelaltaqi Linux - Newbie 5 03-27-2008 10:05 PM
c++ get() delimiter ashirazi Programming 3 08-06-2004 05:26 AM
tab delimiter codename000 Programming 3 04-04-2003 10:18 AM


All times are GMT -5. The time now is 11:10 PM.

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