LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How use CUT -d 'delimiter' is delimiter is a TAB? (https://www.linuxquestions.org/questions/programming-9/how-use-cut-d-delimiter-is-delimiter-is-a-tab-720186/)

frenchn00b 04-19-2009 07:54 AM

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

frenchn00b 04-19-2009 07:56 AM

[ SOLVED ]
Quote:

Originally Posted by frenchn00b (Post 3514022)
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 ]

raskin 04-19-2009 10:18 AM

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

ghostdog74 04-19-2009 11:19 AM

you can also use awk.

sr71919 01-31-2010 02:03 AM

press "<CTR> v" then the "<TAB>" key

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

frenchn00b 02-01-2010 06:26 PM

Quote:

Originally Posted by sr71919 (Post 3846878)
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

tuxdev 02-01-2010 09:07 PM

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"

jschiwal 02-01-2010 09:25 PM

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-

sabata.descordada 03-30-2010 07:25 AM

I use the awk
 
grep "833" session_20100321.log | awk '{ FS = "\t" ; printf(" %s %s\n", $5,$6); }'

grail 03-30-2010 08:44 AM

If your looking to use with ps then:

Code:

ps aux | awk '{ print $1}'
works :)

m3n78am 10-08-2013 01:49 AM

use this
 
cut -d$'\t'

NevemTeve 10-08-2013 03:00 AM

When not in bash, use printf:

Code:

TAB=$(printf '\t')
echo "here  is a $TAB" | od -tx1


sergani 11-06-2013 03:17 AM

Quote:

Originally Posted by grail (Post 3917934)
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!


All times are GMT -5. The time now is 02:57 AM.