nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell Script For Splittting String

This is a discussion on Shell Script For Splittting String within the Shell scripting forums, part of the Development/Scripting category; Hi guys and gals iam having a string e.g cat,name,item,class,supplier,supplier2 i want to split this string for ',' comma characher ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 16-06-2009, 02:53 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
bipin is on a distinguished road
Default Shell Script For Splittting String

Hi guys and gals

iam having a string e.g cat,name,item,class,supplier,supplier2 i want to split this string for ',' comma characher using shell script i want to store the string in array,
plz give me shell script to perform above operations.
Reply With Quote
  #2 (permalink)  
Old 16-06-2009, 06:32 PM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
bipin is on a distinguished road
Thumbs up

Code:
colname=`echo $GIS_OPT_COLOUMNNAME`
colnames=(`echo $colname | tr ',' ' '`)
#echo "the values of array is ${colnames[@]} "

Last edited by nixcraft; 16-06-2009 at 06:42 PM.
Reply With Quote
  #3 (permalink)  
Old 16-06-2009, 06:43 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You can also use cut command.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #4 (permalink)  
Old 18-06-2009, 09:38 AM
Junior Member
User
 
Join Date: Jun 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
bipin is on a distinguished road
Thumbs up

The cut command doest not allow the special charcters lile '@'.
Reply With Quote
  #5 (permalink)  
Old 18-06-2009, 03:17 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by bipin View Post
The cut command doest not allow the special charcters lile '@'.
As a delimiter?
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #6 (permalink)  
Old 25-06-2009, 04:26 AM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 82
Thanks: 0
Thanked 16 Times in 16 Posts
Rep Power: 3
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default


Code:
string='cat,name,item,class,supplier,supplier2'
IFS=,
array=( $string )
Reply With Quote
Reply

Tags
cut , linux , shell scripting , tr command , unix


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
String manipulation Gideon Shell scripting 19 31-05-2009 01:50 AM
Shell Script for Searching a String vivekv Shell scripting 7 10-03-2009 03:18 AM
Binary Conversion Of Shell Script (shell script compiler) chandanperl Shell scripting 3 29-07-2008 10:22 AM
split files by specifying a string (bash shell) vikas027 Shell scripting 4 01-11-2007 04:22 PM
example for string connect to a command. ryan Shell scripting 2 22-02-2005 01:05 PM


All times are GMT +5.5. The time now is 03:46 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38