LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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, 10: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, 10: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, 04:43 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
Quote:
Originally Posted by frenchn00b View Post
Is there any solutiosn? (no perl)
no.
cut takes a single char.
 
Old 04-20-2009, 04: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 04:41 AM.
 
Old 04-20-2009, 05:31 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
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, 05:44 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
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, 11: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 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


All times are GMT -5. The time now is 09:33 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration