Sed subsitution on loop output in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed subsitution on loop output in shell script
# 1  
Old 09-27-2008
Sed subsitution on loop output in shell script

I have a forloop which checks a log for a set of 6 static IP addresses and each IP found is logged to a file which is then mailed to me.

After the forloop I always have a text file that may contain up to 6 IP addresses or may contain 0.
What I want to do is substitute the IP addresses (if any) into their hostnames so that the mail is more readable.

I was trying to use sed to accomplish this but i was having trouble getting the right result.
Any tips on how to do this or is sed even the best tool to use?

Thanks
# 2  
Old 09-27-2008
How about something like:

Code:
for i in `cat file`
   do
       nslookup ${i} "format options here" >> file.another
   done

# 3  
Old 09-28-2008
Interesting nslookup might just do the trick, I'll give it a try.
Thanks for the suggestion.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script, For loop output to excel as columns

Hi, I have a shell script which analyses the log folder for a specific string and throws me the output. I have used for loop since it does this in multiple servers. Now I want to save the output in a excel in the below format. Can someone please help? The output which I get Server1 : count... (14 Replies)
Discussion started by: srilaxman
14 Replies

2. Shell Programming and Scripting

Printing the output of sed using a loop

So I am writing a bash script that will search a file line by line for unix timestamps, store all of the timestamps into an array, then check how many of those timestamps were created within the last hour, and finally increment a counter every time it finds a timestamp created within the last hour.... (6 Replies)
Discussion started by: jsikarin
6 Replies

3. Shell Programming and Scripting

How to get the for loop output from a remote server in UNIX shell scripting?

Hi, I am using ksh , when i try to use for loop i am getting the expected output. $for variable in $(ps -fu user | grep -i something/ | grep -i something | grep -v grep | awk '{print $2}');do > grep $variable /tmp/some_path/*/* > done when tried the below to remote server, getting... (4 Replies)
Discussion started by: karthikram
4 Replies

4. Shell Programming and Scripting

Loop with output to script?

Hey guys, I am VERY new to linux scripting and was wondering if you could help me with the following: essentially the use case is the following...a service crashes and a script must be executed to rerun 3000 entries one at a time....your options are to do each of those manually, 1 at a time... (6 Replies)
Discussion started by: wrnganswr
6 Replies

5. UNIX for Dummies Questions & Answers

Print each output of loop in new column using awk or shell

I have this output from a loop a11 1,2 3,4 5,6 7,8 12,8 5,4 3,6 a12 10,11 12,13 15,18 20,22 a13 ... (3 Replies)
Discussion started by: maryre89
3 Replies

6. Shell Programming and Scripting

sed not storing output in shell script

Hello, Following my learning of shell scripting.. I got stuck yet again. If I execute this command on terminal: $ sed "s/off/on/g" file > fileAUX I successfully change the text off to on from file to fileAUX. But the same command is not working inside a shell script. I tested and... (2 Replies)
Discussion started by: quinestor
2 Replies

7. Shell Programming and Scripting

Help, while loop and sed not producing desired output

Hello everyone, I need some assistance with what I thought would have been a very simple script. Purpose of Script: Script will parse through a source file and modify (search/replace) certain patterns and output to stdout or a file. Script will utilize a "control file" which will contain... (12 Replies)
Discussion started by: packetjockey
12 Replies

8. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

9. Shell Programming and Scripting

sed in while loop producing arithmetic output

Hi all Just wondering if someone can help me with this. I'm trying to write a script that processes the output of another file and prints only the lines I want from it. This is only the second script I have written so please bare with me here. I have referred to the literature and some of the... (3 Replies)
Discussion started by: javathecat
3 Replies

10. Shell Programming and Scripting

using the sed command with variable subsitution???

how much do you know on using the sed commands within a diff command? I'm currently using one long command when robot runs that... when the diff command is ran that the < and > signs at the beginning of each line are changed to the environment name that they came from... making it easier to... (2 Replies)
Discussion started by: anthreedhr
2 Replies
Login or Register to Ask a Question