Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-28-2006, 10:38 PM   #1
Registered: Feb 2002
Distribution: Gentoo
Posts: 95

Rep: Reputation: 15
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?

Last edited by mathfeel; 11-28-2006 at 10:39 PM.
Old 11-28-2006, 10:55 PM   #2
LQ Guru
Registered: Aug 2001
Location: Dublin, Ireland
Distribution: Slackware
Posts: 5,700

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

Here's an example:

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


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?




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
regexp question: first instance for each line buldir Programming 6 03-20-2006 01:20 PM
Regexp question scuffell Programming 4 04-30-2005 03:35 AM
postfix regexp question wijnands Linux - Newbie 1 06-03-2004 06:19 AM
grep question Hockeyfan Linux - General 1 05-15-2004 02:09 AM
regexp question rytrom Linux - Newbie 3 09-01-2003 12:50 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:20 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration