LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How use CUT with several chars delimiter (not a single char) ? (https://www.linuxquestions.org/questions/programming-9/how-use-cut-with-several-chars-delimiter-not-a-single-char-720196/)

frenchn00b 04-19-2009 09:10 AM

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)

frenchn00b 04-19-2009 09:12 AM

if found for the moment, this solution only:

Code:

cat myfile.txt | awk -F" : " '{print $1; print $2}'

bigearsbilly 04-19-2009 03:43 PM

Quote:

Originally Posted by frenchn00b (Post 3514078)
Is there any solutiosn? (no perl)

no.
cut takes a single char.

ta0kira 04-20-2009 03:37 AM

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

gnashley 04-20-2009 04:31 AM

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


ghostdog74 04-20-2009 04:44 AM

maybe i am blind, but where in your data do you have " : " delimeter?

kike_coello 04-22-2009 10:11 PM

True that, you only have:
"f:/"

not :
"f : /"


All times are GMT -5. The time now is 02:26 PM.