LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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, 09:10 AM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

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


Hello

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

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

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

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

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by frenchn00b View Post
Is there any solutiosn? (no perl)
no.
cut takes a single char.
 
Old 04-20-2009, 03:37 AM   #4
ta0kira
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.
Code:
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?
Code:
echo 'one = target' | sed 's/ = /@/g' | cut -d'@' -f2
Kevin Barry

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

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
Code:
#!/bin/bash

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*}
	echo
done <myfile.txt
 
Old 04-20-2009, 04:44 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

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

Rep: Reputation: 17
True that, you only have:
"f:/"

not :
"f : /"
 
  


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


All times are GMT -5. The time now is 09:28 AM.

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