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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-21-2004, 06:06 PM
|
#1
|
Member
Registered: Jul 2004
Posts: 171
Rep:
|
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?
|
|
|
12-21-2004, 06:26 PM
|
#2
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
I'd use Awk, personally...
Cheers,
mj
|
|
|
12-21-2004, 06:36 PM
|
#3
|
Member
Registered: Jul 2004
Posts: 171
Original Poster
Rep:
|
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?
|
|
|
12-21-2004, 06:50 PM
|
#4
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,795
|
Or you can use sed then cut ...
|
|
|
12-21-2004, 06:57 PM
|
#5
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
|
|
12-21-2004, 07:05 PM
|
#6
|
Senior Member
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046
Rep:
|
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.
|
|
|
12-21-2004, 07:09 PM
|
#7
|
Member
Registered: Jul 2004
Posts: 171
Original Poster
Rep:
|
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
|
|
|
12-21-2004, 07:18 PM
|
#8
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
|
|
12-21-2004, 07:27 PM
|
#9
|
Member
Registered: Jul 2004
Posts: 171
Original Poster
Rep:
|
Thank you very much. That worked great.
|
|
|
12-21-2004, 07:38 PM
|
#10
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Pleasure ;)
Cheers,
Tink
|
|
|
All times are GMT -5. The time now is 08:52 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|