LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 12-21-2004, 06:06 PM   #1
krock923
Member
 
Registered: Jul 2004
Posts: 171

Rep: Reputation: 30
cut with multiple character delimeter


For a script I'm writing, I need to use cut and " / " as the delimeter. [space,slash,space]. Obviously, this won't work with the cut command so is there any other command that is better suited for something like this?
 
Old 12-21-2004, 06:26 PM   #2
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
I'd use Awk, personally...

Cheers,

mj
 
Old 12-21-2004, 06:36 PM   #3
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
I don't know enough about awk to know how to do that. If that's the way to go, could you please post some example code or seome general guidelines?
 
Old 12-21-2004, 06:50 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Or you can use sed then cut ...
 
Old 12-21-2004, 06:57 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by krock923
I don't know enough about awk to know how to do that. If that's the way to go, could you please post some example code or seome general guidelines?
How's that:

You post sample data, I post sample awk usage :}


Cheers,
Tink
 
Old 12-21-2004, 07:05 PM   #6
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
Following on from jlliagre's suggestion, you could use something along the lines of
Code:
cat test | tr -s '[:space:]/[:space:]' '@'| cut -d @ -f <field_no>
...assuming you don't have any spare @'s in your datafile.
 
Old 12-21-2004, 07:09 PM   #7
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
here is the original line

DTITLE=Various Artists / Kohl's - Songs Of The Season 2000

this is what i have so far

grep DTITLE cdinfo.txt | cut -d '=' -f 2

which produces this line:

Various Artists / Kohl's - Songs Of The Season 2000
 
Old 12-21-2004, 07:18 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by krock923
here is the original line

DTITLE=Various Artists / Kohl's - Songs Of The Season 2000

this is what i have so far

grep DTITLE cdinfo.txt | cut -d '=' -f 2

which produces this line:

Various Artists / Kohl's - Songs Of The Season 2000
Code:
FIELD1=`grep DTITLE cdinfo.txt | cut -d '=' -f 2 | awk 'BEGIN{ FS=" / "}{print $1}'`
FIELD2=`grep DTITLE cdinfo.txt | cut -d '=' -f 2 | awk 'BEGIN{ FS=" / "}{print $2}'`


Cheers,
Tink
 
Old 12-21-2004, 07:27 PM   #9
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Thank you very much. That worked great.
 
Old 12-21-2004, 07:38 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Pleasure ;)


Cheers,
Tink
 
  


Reply



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
cut question krock923 Programming 1 10-19-2005 04:03 PM
Ls and cut problem Phiebie Debian 2 07-14-2005 07:10 AM
Between sessions: cut/paste, multiple on one screen, dual monitors Z505 Linux - General 0 04-03-2005 01:42 PM
winkey mapped to multiple character input g-off Linux - General 0 02-24-2004 02:26 AM
Ok, maybe I'm not cut out for linux... goosegg Linux - Newbie 5 09-01-2003 03:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:49 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
Open Source Consulting | Domain Registration