LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   grep regexp question (https://www.linuxquestions.org/questions/linux-software-2/grep-regexp-question-505759/)

mathfeel 11-28-2006 10:38 PM

grep regexp question
 
I am trying to extract a column from a command-separated table. How do I use grep or egrep or sed or whatever tool to extract the text (unicode, contain Chinese character sometimes) between says, the n-th and the (n+1)-th comma?

finegan 11-28-2006 10:55 PM

You're looking for "cut" You can declare an arbitrary delimeter with -d.

Here's an example:

Code:

fin@sleepy:~$ cat foo
bob,jack, tom, ed
bob,  jack, tom, ed
bob,  jack, tom, ed
bob, mike, jack, tom, ed
bob, coffee,  jack, tom, ed

fin@sleepy:~$ cat foo | cut -d , -f2-3
jack, tom
  jack, tom
  jack, tom
 mike, jack
 coffee,  jack

or...

fin@sleepy:~$ cat foo | cut -d , -f1-3
bob,jack, tom
bob,  jack, tom
bob,  jack, tom
bob, mike, jack
bob, coffee,  jack

Where -f controls the fields you want outputted.

Is that what you were lookin for?

Cheers,

Finegan


All times are GMT -5. The time now is 04:45 AM.