tags:

views:

1976

answers:

3

Hi, If I want to cut a list of text using a string as a delimiter, is that possible. For e.g. I have a directory where a list of shell scripts call same perl script say abc.pl So when I do $grep abc.pl * in that directory, it gives me following results xyz.sh: abc.pl 1 2 xyz2.sh: abc.pl 2 mno.sh: abc.pl 3 pqr.sh: abc.pl 4 5

I basically want all the output after "abc.pl" (to check what range arguments are being passed to the perl right now)

When I tried $grep abc.pl * | cut -d'abc.pl' -f2 OR $grep abc.pl * | cut -d'abc.pl' -f2 its giving me cut: invalid delimiter

When I read man for cut it states ... delim can be a multi-byte character. ... What am I doing/interpreting wrong here?

Thanks. Devang Kamdar.

+1  A: 

why not use grep abc.pl | awk '{print $3, $4}'?

alamar
not really working the way I am expecting it to show results.Its showing partial list ... also am curious whats wrong with the way I am using cut?
Devang Kamdar
I've never in fact used cut. Your task shouts for awk or perl!
alamar
Cool ... Thanks alamar ... however I am gonna give the correct answer to Alex's response, as he really answered what I was looking for. I wish there was a way to select two answers ... but then it would cause many other probs. So thanks for your help. Really appreciate it :)
Devang Kamdar
No problem, I don't really care about that scoring thing.
alamar
good to know ... but its just that if someone else comes looking for an answer to the same problem, reading both the posts would give complete solution. Anyways ... assuming they would look at other replies too if their problem is not solved by looking at first one :)
Devang Kamdar
+1  A: 

When I read man for cut it states ... delim can be a multi-byte character.

Multi-byte, but just one character, not a string.

canti:~$ ll | cut --delimiter="delim" -f 1,2
cut: the delimiter must be a single character
Try `cut --help' for more information.

canti:~$ cut --version  
cut (GNU coreutils) 5.97

You can specify only output delimiter as a string (useless in this case):

 --output-delimiter=STRING                                                          
        use STRING as the output delimiter the default is to use the input delimiter
alex vasi
Thanks Alex ....
Devang Kamdar
A: 

$ grep abc.pl * | cut -d' ' -f3-999

In that case just use the space character as the delimiter.

wdingus
No need to include `999` - just do `cut -d' ' -f3-`.
jnylen