perl line needing a tweak


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl line needing a tweak
# 1  
Old 05-31-2012
perl line needing a tweak

Hi Folks,

I have a perl line that looks like this and it works fine as is, but I need it to expand a bid further.

Code:
perl -aF, -ne 'printf "conf zone %2\$s delete host %s,,,$F[3]\n",split/\./,$F[1],2 if /^hostrecord/ &&/\b10\.8\.([3469]|1[0234])\.\d/' hosts.csv

this code the way it is does this
10.8.3.0
10.8.4.0
10.8.6.0
10.8.9.0
10.8.10.0
10.8.12.0
10.8.13.0
10.8.14.0

But I somehow need it to branch further down.
10.8.0.0/16, ranging through 10.14.0.0/16

meaning the entire octet from 10.8.x.x 10.9.x.x 10.10.x.x 10.11.x.x 10.12.x.x 10.13.x.x 10.14.x.x

short Example
10.8.9.0
10.8.10.0
10.9.1.0
10.9.2.0
.....
10.11.249.0
10.11.249.64
10.11.254.128
...
10.12.0.0
10.13.0.0
10.14.0.0
and so on until 10.14.0.0

Thanks in advance !
# 2  
Old 06-01-2012
Try this:

Code:
perl -aF, -ne 'printf "conf zone %2\$s delete host %s,,,$F[3]\n",split/\./,$F[1],2 if /^hostrecord/ &&/\b10\.([89]|1[01234])\.([3469]|1[0234])\.\d/' hosts.csv

# 3  
Old 06-01-2012
Hey, Thanks for that, I just ran it...

I cant seem to understand why the below does not come out in the routine. This is just one I hand picked. Not sure if there are more
Code:
hostrecord,rich.sark.com,,10.8.2.1,,,,,,,True,,False,,,,,,,,,,,,,default
hostaddress,10.8.2.1,,rich.sark.com,,,,False,,,,,,,,,,,,default

Here is a small excerpt
Code:
hostrecord,acf0535r01.homeoffice.anfcorp.com,,10.8.202.10,,,,,,,True,,False,,,,,,,,,,,,,default
hostaddress,10.8.202.10,,acf0535r01.homeoffice.anfcorp.com,,,,False,,,,,,,,,,,,default
hostrecord,acf0535r02.homeoffice.anfcorp.com,,10.8.202.11,,,,,,,True,,False,,,,,,,,,,,,,default
hostaddress,10.8.202.11,,acf0535r02.homeoffice.anfcorp.com,,,,False,,,,,,,,,,,,default
hostrecord,acf0535r03.homeoffice.anfcorp.com,,10.8.202.12,,,,,,,True,,False,,,,,,,,,,,,,default
hostaddress,10.8.202.12,,acf0535r03.homeoffice.anfcorp.com,,,,False,,,,,,,,,,,,default
hostrecord,acf0535r04.homeoffice.anfcorp.com,,10.8.202.13,,,,,,,True,,False,,,,,,,,,,,,,default
hostaddress,10.8.202.13,,acf0535r04.homeoffice.anfcorp.com,,,,False,,,,,,,,,,,,default
hostaddress,10.11.18.3,,a10792-prnt01.stores.anfcorp.com,,,,False,,,,,,,,,,,,default
hostrecord,a10793-prnt01.stores.anfcorp.com,,10.10.133.131,,,,,,,True,,False,,,,,,,,,,,,,default
hostaddress,10.9.22.55,,a10935-prnt01.stores.anfcorp.com,,,,False,,,,,,,,,,,,default
hostrecord,a10935-prnt02.stores.anfcorp.com,,10.1.96.24,,,,,,,True,,False,,,,,,,,,,,,,default


Last edited by Franklin52; 06-01-2012 at 03:41 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 06-01-2012
Sorry based criteria for the 2nd last digit of IP address on original string. If your happy with "x" in 10.8.x.x to be any string of numbers then try this:

Code:
perl -aF, -ne 'printf "conf zone %2\$s delete host %s,,,$F[3]\n",split/\./,$F[1],2 if /^hostrecord/ &&/\b10\.([89]|1[01234])\.\d+\.\d+/' hosts.csv

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 06-01-2012
Sorry... I need it to stop once this is reached 10.14.x.x

Sorry for the confusion.

Will this new one do that?

Last edited by richsark; 06-01-2012 at 01:07 AM.. Reason: correction
# 6  
Old 06-01-2012
It will stop at 10.14.255.255 (well actually 10.14.999999.999999 but you shouldn't have any ip addresses like that).
This User Gave Thanks to Chubler_XL For This Post:
# 7  
Old 06-01-2012
Awesome, let me play with it, say... is there a way for the IP's to sort from 10.8.x.x to 10.14.x.x?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Tar.gz help - Need to tweak

Hi Guys - I need help tweaking my tar.gz process. Currently, I compress all files in a directory, in which the parent directory is included in that. I only want to compress the "*.txt" files in the follow process: tar -zcvf ${_ESSB_TAR_PATH}/Essbase_Exports_${_DATETIMESTAMP}.tar.gz -C /... (3 Replies)
Discussion started by: SIMMS7400
3 Replies

2. Shell Programming and Scripting

Perl find command tweak

i use the following command to find files that were recently updated within the last hour: perl -MFile::Find -le' find { wanted => sub { -f and 3600 / 86400 >= -M and print $File::Find::name; } }, shift' /var/app/mydata/ this command works well. however, it seems to also search directories... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

SED script needs tweak

I have a SED script that has worked for years, but broke today due to a new variable in a remote file. This is the part of the script that now won't work: sed "s|/directory/overview.gif|/directory/img/overview2.gif|g" | \ The path /directory/overview.gif is no longer static as it had been... (2 Replies)
Discussion started by: dockline
2 Replies

4. Shell Programming and Scripting

Needing to wait for a line on screen and then give input repeatedly

So I have a weird question for my unix shell script. I wrote a shell script that does several things, but one of the things it does is call an executable. The executable then proceeds to start asking me questions, which it won't proceed until an input is entered. The answer to the questions is... (4 Replies)
Discussion started by: HelpMeProgram
4 Replies

5. Shell Programming and Scripting

How to tweak up

I have a script like this: while read abbrev; do sed 's/'$(echo "$abbrev" | tr "" "")'/'"$abbrev"'/g' 'output_rgt.'$$ >'tmp.'$$ mv 'tmp.'$$ 'output_rgt.'$$ done<'dict.shortcuts.'$$ And I don't know how to leave "mv" out. ('dict.shortcuts.'$$ may be... (14 Replies)
Discussion started by: MartyIX
14 Replies

6. UNIX for Dummies Questions & Answers

Intern needing to convert bash to perl.

Hello All. I am very new to Linux and I am currently interning. I have been working on a project for a week and I have had no success. I have to convert bash shell into perl to decrypt and store files. Here is the code in Linux and Bash. Any help would be greatly appreciated. $... (0 Replies)
Discussion started by: freak
0 Replies

7. Shell Programming and Scripting

Needing a line feed for windows app

I wrote a program to format data with awk. This file will goto a windows machine and loaded into a windows app. The vendor said adding a line feed would help, but it would work as is. I am already doing a /n, will putting on the /r give the windows person what he wants. Thanks. (5 Replies)
Discussion started by: benefactr
5 Replies
Login or Register to Ask a Question