Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 57
How use CUT with several chars delimiter (not a single char) ?


myfile.txt contains:
string1 = stri/*-sdf:/()()/*'##+ng2
string1 = stri/*-sdf:/()()/*'##+ng2
I would like to cut as if:
cat myfile.txt | cut -d" : " -f1
but -d should be a single char.

Is tehre any solutiosn? (no perl)
Old 04-19-2009, 10:12 AM   #2
Senior Member
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 57
if found for the moment, this solution only:

cat myfile.txt | awk -F" : " '{print $1; print $2}'
Old 04-19-2009, 04:43 PM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
Originally Posted by frenchn00b View Post
Is there any solutiosn? (no perl)
cut takes a single char.
Old 04-20-2009, 04:37 AM   #4
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Try using tr 'chars' 'char' to preprocess, e.g.
echo 'one,two three|target' | tr ',|' ' ' | cut -d' ' -f4
This might not be what you mean; I can't tell. Maybe you mean a sequence is the delimiter?
echo 'one = target' | sed 's/ = /@/g' | cut -d'@' -f2
Kevin Barry

Last edited by ta0kira; 04-20-2009 at 04:41 AM.
Old 04-20-2009, 05:31 AM   #5
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,874

Rep: Reputation: 554Reputation: 554Reputation: 554Reputation: 554Reputation: 554Reputation: 554

SEP=' : '
echo SEP="'$SEP'"
while read line ; do
	echo right-of-first=${line#*$SEP}
	echo right-of-last=${line##*$SEP}
	echo left-of-first=${line%%$SEP*}
	echo left-of-last=${line%$SEP*}
done <myfile.txt
Old 04-20-2009, 05:44 AM   #6
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
maybe i am blind, but where in your data do you have " : " delimeter?
Old 04-22-2009, 11:11 PM   #7
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Rep: Reputation: 17
True that, you only have:

not :
"f : /"


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
How use CUT -d 'delimiter' is delimiter is a TAB? frenchn00b Programming 12 11-06-2013 04:17 AM
Need 'cut' with mulit char delimiter endfx Programming 5 03-04-2009 02:37 AM
single quotes represented by garbage chars in perldoc echowarpt Slackware 3 05-26-2007 12:03 PM
how to add two unsigned chars in a char aizkorri Programming 3 07-04-2006 04:17 PM
char array of size 10 can read morethan 10 chars!!!!! pippet Programming 13 07-12-2004 02:44 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:11 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