LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 06-27-2008, 04:07 AM   #1
raghuvamsi
LQ Newbie
 
Registered: May 2008
Posts: 20

Rep: Reputation: 0
need help in scripting.....


hi all
I have to write a script, which will copy data (IP addresses) from IP_ADDRS file to different files (one IP address will be copped to one file).

IP_ADDRS file

IP_SYS1=193.168.1.1
IP_SYS2=193.168.1.2
IP_SYS3=193.168.1.3
IP_SYS4=193.168.1.4
IP_SYS5=193.168.1.5
IP_SYS6=193.168.1.6
IP_SYS7=193.168.1.7
IP_SYS8=193.168.1.8

And device details.

--------------------------------

Each address should be copped one file like

IP_SYS1 to sys1.txt

IP_SYS2 to sys2.txt

The sys1.txt should look like

IP_ADDR= 193.168.1.1

The sys2.txt should look like

IP_ADDR= 193.168.1.2

I wrote two scripts do this. But I need to do this with a single script.

please suggest me one procedure to do this using a single script.


Thank you.
 
Old 06-27-2008, 04:49 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Can you post the scripts you wrote? Maybe you can easily put them together. Anyway, my personal solution would be
Code:
#!/bin/bash
while read line
do
  file=$(echo ${line%=*} | cut -c 4- | tr '[A-Z]' '[a-z]').txt
  echo "IP_ADDR= ${line#*=}" > $file
done < IP_ADDRS
 
Old 06-27-2008, 04:59 AM   #3
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 38
You could try something like this:
Code:
awk -F'[_=]' '{
  printf "IP_ADDR= %s\n", 
    $3 > tolower($2)".txt"
}' ip_addrs_file
If the ip_addrs_file is too large,
use this:

Code:
awk -F'[_=]' '{
  print f, $2
  close(f)
  printf "IP_ADDR= %s\n", 
    $3 > (f = tolower($2)".txt")
}' ip_addrs_file
 
  


Reply



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
I am new to scripting PKrishna Linux - Newbie 7 03-17-2008 09:39 PM
Scripting aznium Programming 17 09-03-2006 01:37 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
scripting bforest Linux - Newbie 4 05-11-2004 02:45 AM
scripting help versaulis Linux - Software 8 11-22-2003 07:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration