![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 01:25 PM |
| awk - split function | fusionX | Shell Programming and Scripting | 7 | 04-10-2008 03:32 AM |
| split files by specifying a string (bash shell) | vikas027 | Shell Programming and Scripting | 12 | 11-01-2007 01:57 PM |
| perl split function | new2ss | Shell Programming and Scripting | 5 | 06-08-2006 11:17 PM |
| split function | ktsirig | UNIX for Dummies Questions & Answers | 4 | 09-29-2005 11:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
perl split function for bash?
Hi! I'm doing bash shell scripting and would like to know if bash had something similar to perl's split function? Ultimately, I want to split two strings (delimeter = '.') and compare each of their values. Thus, I figured putting them in an array would be easiest.
So i.e.: String 1: 21.14.51 String 2: 20.15.21 I want to get: Array1: [21][14][51] Array2: [20][15][21] So that I can run a for-loop to compare the values. Does anyone recommend any other method for doing this? Last edited by eur0dad; 07-15-2006 at 06:16 PM.. |
|
||||
|
#!/bin/bash
# Split the command line argument on the colon character. SaveIFS=$IFS IFS=":" declare -a Array=($*) IFS=SaveIFS echo "Array[0]=${Array[0]}" echo "Array[1]=${Array[1]}" echo "Array[2]=${Array[2]}" echo "Array[3]=${Array[3]}" |
|
||||
|
Go to:
bash shell script split array - LinuxQuestions.org And see: IP=1.2.3.4; IP=(${IP//./ }); Rev=${IP[3]}.${IP[2]}.${IP[1]}.${IP[0]} |
![]() |
| Bookmarks |
| Tags |
| bash, perl split, shell scripting, tokenize |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|