Sponsored Content
Full Discussion: loop issue
Top Forums Shell Programming and Scripting loop issue Post 302210900 by Sergiu-IT on Wednesday 2nd of July 2008 08:05:57 AM
Old 07-02-2008
Hi !

Asuming that you are sure that you have the same number of lines on both files, and every record is on a single line, you can use the following script:

Code:
#!/usr/bin/perl -w
#

open(MACS,"mac.txt") or die("Could not open mac.txt");
open(IPS,"ip.txt") or die("Could not open ip.txt");
open(RESULT,">result.txt") or die("Could not open result.txt");

my @macs = ();
my @ips = ();

push(@macs,$_) while( <MACS> );
push(@ips,$_)  while( <IPS> );

chomp(@macs);
chomp(@ips);

for( $i=0 ; $i<=$#macs ; $i++ ){
    print RESULT "host www$i.domain.com {\n";
    print RESULT "hardware ethernet $macs[$i];\n";
    print RESULT "fixed-address $ips[$i];\n";
    print RESULT  "}\n\n";
}

close(MACS);
close(IPS);
close(RESULT);

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help With A For Loop Issue

I was wondering how I can modify this for loop, so it only loops through the filenames that do not have an ".old" extension. for filename in $(ls "$1") do echo $filename | grep '\.old$' > /dev/null if then mv $1/$filename $1/$filename.old fi done (5 Replies)
Discussion started by: ralts01
5 Replies

2. Shell Programming and Scripting

while loop issue

Hi, Following is my code and the file FILE_LIST_EXCESS.txt has 40 file names in it while read LineIn do echo ${LineIn} `ftp -vin << END_INPUT >> ${PID}_DS_GET_Log.log 2>&1 open servername user userid password cd FileDir get ${LineIn} END_INPUT`... (4 Replies)
Discussion started by: mgirinath
4 Replies

3. Shell Programming and Scripting

loop issue

function ext { echo "THANKS & WELCOME BACK" } function upc { echo "TO EXPORT UPROC GIVE UPROC NAME PER LINE IN THE input.txt and PRESS Y" echo "TO GO BACK PRESS 99" read parm0 if ; then start elif ; then for i in `cat input.txt` ; do echo $i $UXEXE/uxext upr upr=$i... (0 Replies)
Discussion started by: kojo
0 Replies

4. Shell Programming and Scripting

until loop issue.

Hi, my script is waiting for 3 files to come to a folder for 30 min but even when all the files arrive in the folder it's still waiting for these three files. Files can come with in 2 min and I want it to start processing them immediately after all the files arrive in the folder. until ; do... (3 Replies)
Discussion started by: gurpartap
3 Replies

5. Shell Programming and Scripting

for-while loop issue

sup experts..i had a script which was bugging me..was hoping someone could point out the issue here Input file: space separated 2 columns I wanted to print out the 2 columns after assigning them to variables ( bascially the same output but iterate through line by line ). The code worked... (7 Replies)
Discussion started by: foal_newbie
7 Replies

6. Shell Programming and Scripting

Issue with using While loop

Hi, I am trying to move a file from remote server to local server and when the transfer completes successfully i call a script in remote server to remove the file which was successfully transferred. I do this by first getting the list of file in remote server and move the text file to local... (8 Replies)
Discussion started by: funonnet
8 Replies

7. Shell Programming and Scripting

While Loop issue

Hi, i=0 t5=6000001 while do i=`expr $i + 1` t5=`expr $t5 + 1` echo $t5 done I am able to increment "col3" value but unable to get col1,col2 value. Input: t1=10001 t2=abc t3=ghkc (5 Replies)
Discussion started by: onesuri
5 Replies

8. Shell Programming and Scripting

Issue with while loop?

Hi, I have prepared a script to search for backup file information on the Linux server. Script works fine for the most part except the echo statement inside an IF conditional block displays the message ''snapshot directory not found on xxxxx" even though the .snapshot directory is found a... (11 Replies)
Discussion started by: svajhala
11 Replies

9. Shell Programming and Scripting

Issue with for loop

Hi Team, I have for loop in my shell script. Which basically loop through all files in the directory, When some files are in the directory it works just fine. But if there are no files at all..still the for loop try to execute. Please help. Below is the code. #!/bin/ksh echo "Program... (5 Replies)
Discussion started by: bharath561989
5 Replies

10. UNIX for Beginners Questions & Answers

Issue when doing a loop

Hi, I just have started learning shell scripting (sh). Why do i only get the date? while read dt do echo "Date : ${dt} sed -n '/${dt}/,/${dt}/p' file1.log | grep -w ERROR done < date1.dat INPUT - date1.dat 2019-04-05 04:58:25 2019-04-05 04:58:26 2019-04-05 05:00:56... (3 Replies)
Discussion started by: margel
3 Replies
RAR_LIST(3)								 1							       RAR_LIST(3)

RarArchive::getEntries - Get full list of entries from the RAR archive

       Object oriented style (method):

SYNOPSIS
public array RarArchive::getEntries (void ) DESCRIPTION
Procedural style: array rar_list (RarArchive $rarfile) Get entries list (files and directories) from the RAR archive. Note If the archive has entries with the same name, this method, together with RarArchive foreach iteration and array-like access with numeric indexes, are the only ones to access all the entries (i.e., RarArchive::getEntry and the rar:// wrapper are insufficient). PARAMETERS
o $rarfile - A RarArchive object, opened with rar_open(3). RETURN VALUES
rar_list(3) returns array of RarEntry objects or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 3.0.0 | | | | | | | Support for RAR archives with repeated entry | | | names is no longer defective. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 Object oriented style <?php $rar_arch = RarArchive::open('solid.rar'); if ($rar_arch === FALSE) die("Could not open RAR archive."); $rar_entries = $rar_arch->getEntries(); if ($rar_entries === FALSE) die("Could retrieve entries."); echo "Found " . count($rar_entries) . " entries. "; foreach ($rar_entries as $e) { echo $e; echo " "; } $rar_arch->close(); ?> The above example will output something similar to: Found 2 entries. RarEntry for file "tese.txt" (23b93a7a) RarEntry for file "unrardll.txt" (2ed64b6e) Example #2 Procedural style <?php $rar_arch = rar_open('solid.rar'); if ($rar_arch === FALSE) die("Could not open RAR archive."); $rar_entries = rar_list($rar_arch); if ($rar_entries === FALSE) die("Could retrieve entries."); echo "Found " . count($rar_entries) . " entries. "; foreach ($rar_entries as $e) { echo $e; echo " "; } rar_close($rar_arch); ?> SEE ALSO
RarArchive::getEntry, rar:// wrapper. PHP Documentation Group RAR_LIST(3)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy