LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
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
 
Thread Tools Search this Thread
Old 11-16-2005, 09:05 PM   #1
robertngo
Member
 
Registered: Mar 2005
Posts: 34
Thanked: 0
bash shell script split array


[Log in to get rid of this advertisement]
Hi,

I need help in making a shell script to modify DNS record, it mostly done but it need a way to split the IP into four part so i can modify reverse zone file.

Any one here can help me with this?
robertngo is offline     Reply With Quote
Old 11-16-2005, 11:26 PM   #2
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213
Thanked: 0
cut with delimiters. or read $1 $2 $3 $4

Last edited by Dave Kelly; 11-16-2005 at 11:27 PM..
Dave Kelly is offline     Reply With Quote
Old 11-17-2005, 02:30 AM   #3
robertngo
Member
 
Registered: Mar 2005
Posts: 34
Thanked: 0

Original Poster
what command can split with deliminater?
robertngo is offline     Reply With Quote
Old 11-17-2005, 03:48 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Puppy
Posts: 2,764
Thanked: 21
cut -d<delimiter> -f<fieldnums>

read the manual page for full info
bigearsbilly is offline     Reply With Quote
Old 11-17-2005, 04:37 AM   #5
robertngo
Member
 
Registered: Mar 2005
Posts: 34
Thanked: 0

Original Poster
it seen like cut need file as input, can i pass the ip address string as input?
robertngo is offline     Reply With Quote
Old 11-17-2005, 04:47 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Puppy
Posts: 2,764
Thanked: 21
Code:
echo 1.2.3.4 | cut -d\. -f3  
3
Code:
(IFS=.;set -- $(echo 192.168.123.444) ;echo $4 $3 $2 $1)
444 123 168 192
bigearsbilly is offline     Reply With Quote
Old 11-17-2005, 02:07 PM   #7
Dave Kelly
Member
 
Registered: Aug 2004
Location: Todd Mission Texas
Distribution: Linspire
Posts: 213
Thanked: 0
Quote:
Originally posted by robertngo
it seen like cut need file as input, can i pass the ip address string as input?
Read here: http://advbash.activeventure.net/index.html
and here: http://www.catb.org/~esr/faqs/smart-questions.html
Dave Kelly is offline     Reply With Quote
Old 09-05-2008, 01:40 PM   #8
jimhertzler
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian
Posts: 2
Thanked: 0
#!/bin/bash
# Linux Aslab 2.6.24-19-generic #1 SMP Wed Aug 20 22:56:21 UTC 2008 i686 GNU/Linux

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]}"
jimhertzler is offline     Reply With Quote
Old 09-05-2008, 02:27 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 16,979
Blog Entries: 33
Thanked: 323
Code:
IP=1.2.3.4; IP=(${IP//./ }); Rev=${IP[3]}.${IP[2]}.${IP[1]}.${IP[0]}
unSpawn is online now     Reply With Quote
1 out of 1 members found this post helpful.
Old 09-05-2008, 03:20 PM   #10
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,336
Thanked: 496
Hmmm... I doubtfully think the OP could be still interested in this topic after 3 years...
colucix is offline     Reply With Quote
Old 09-05-2008, 06:08 PM   #11
jimhertzler
LQ Newbie
 
Registered: Sep 2005
Distribution: Debian
Posts: 2
Thanked: 0
colucix, this question is being asked in other forums also.

unSpawn, thank you. I understand your solution after reading
Learning the bash Shell 2nt ed. by Newham and Rosenblatt page 100.
This is the best solution I have seen anywhere.
Now that I know what to look for, I see the same StringOperation-PatternMatching in the output of `set`.
jimhertzler is offline     Reply With Quote
Old 09-06-2008, 11:11 AM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 16,979
Blog Entries: 33
Thanked: 323
Quote:
Originally Posted by jimhertzler View Post
colucix, this question is being asked in other forums also.
No, he means you revived a stale thread instead of creating your own thread (and maybe linking to this one for reference). And about that Colucix is right.
unSpawn is online now     Reply With Quote

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
Bash Script Array index value Kedelfor Programming 10 04-29-2009 05:37 AM
Bash script text line into an array toolshed Programming 1 06-13-2005 06:49 PM
MAJOR problem ... bash script array HELP !!!!! michael_util Slackware 1 02-13-2004 07:51 AM
shell script array problem rche3252 Programming 1 10-09-2003 12:43 AM
Split function (bash script) NiM Programming 4 10-24-2001 10:02 PM


All times are GMT -5. The time now is 04:15 PM.

Main Menu
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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration