File Parsing using a Shell Script
Hello:
I am very new to shell programming and in need of some help. I have a file sc.cfg that contains some ip addresses as ASCIP. sc.cfg ------------------------------------------- ASCIP=3.87.87.3/255.255.252.0 ASCIP=3.87.86.41/255.255.252.0 ASCIP=3.87.87.45/255.255.252.0 ------------------------------------------- All I need is a shell script that opens this file (sc.cfg) takes out the 3 ip addresses and stores it in etc/hosts... Please help. Thank You & Best Regards |
How about:
grep "ASCIP" sc.cfg | cut -d"=" -f2 | cut -d"/" -f1 >> /etc/hosts The only problem is that you don't have any hostnames so you will need to add them manually. |
hi,
you can use for example awk like this: awk -F"=" {'print $2'} sc.cfg | awk -F"/" {'print $1'} > /etc/hostfile.txt sc.cfg is your enter file , the /etc/hostfile.txt your output file -F"=" option to separte with the symbole =, the second separator is "/", you print the field $1 and in the second the second field best regards bela |
All- Thanks for replying.
Now, if I want to append a variable Name at the start of each ip, how can I go about implementing that ? For example: Var1=3.87.88.3 Var2=3.87.88.41 Var3=3.87.88.42 |
Sorry for taking so long (bit busy now). Try:
Code:
#!/bin/bash |
If reply to your e-mail:
Quote:
Code:
#!/bin/bash |
All times are GMT -5. The time now is 08:58 AM. |