LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-30-2003, 12:34 AM   #1
general4172
Member
 
Registered: Aug 2003
Location: Kansas
Distribution: Red Hat 9.0
Posts: 64

Rep: Reputation: 15
Need to split an input string


I have to split an input string on a common delimiter. I have tried using cut but the problem I run into is that it wants a file. I need to cut the data stored in a variable based upon a certain delimiter.
I tried
cut -d ":" -f 3 "$DATA" but it just keeps looking for a file not taking the string is there another program like cut that I can use or a way to trick cut

Thanks,

John
 
Old 10-30-2003, 12:44 AM   #2
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
you could direct the input to a file and then use cut. are you trying to do this from a script or c/c++? if c++ you could use strtok().
 
Old 10-30-2003, 12:47 AM   #3
general4172
Member
 
Registered: Aug 2003
Location: Kansas
Distribution: Red Hat 9.0
Posts: 64

Original Poster
Rep: Reputation: 15
no I only wish I was doing this in c/c++ its in a bash script. But I can direct it to a file and the read in that file
 
Old 10-30-2003, 12:50 AM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Code:
echo $DATA | cut -d':' -f3
 
Old 10-30-2003, 12:51 AM   #5
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
that looks like it'll work even better.

Last edited by megaspaz; 10-30-2003 at 12:53 AM.
 
Old 10-30-2003, 12:55 AM   #6
general4172
Member
 
Registered: Aug 2003
Location: Kansas
Distribution: Red Hat 9.0
Posts: 64

Original Poster
Rep: Reputation: 15
I thought I had that earlier but I must have misstyped it because it works not. Thanks everyone
 
Old 10-30-2003, 12:57 AM   #7
general4172
Member
 
Registered: Aug 2003
Location: Kansas
Distribution: Red Hat 9.0
Posts: 64

Original Poster
Rep: Reputation: 15
works now
 
  


Reply


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
Split a string on newlines (bash) rose_bud4201 Programming 7 04-14-2005 02:58 PM
split string prob izza_azhar Programming 3 02-08-2005 01:11 AM
split string izza_azhar Programming 6 01-18-2005 09:24 PM
string input tekmorph Programming 3 10-25-2004 09:03 PM
perl string split problem! farhanali Programming 4 06-22-2003 08:08 AM


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