?
Solved

in redhat, waht is an easy way to rotate a file ?

Posted on 2012-09-10
4
Medium Priority
?
336 Views
Last Modified: 2012-09-11
i have a file

host1
host2
host3

after I process host1,

I want the file to read:

host2
host3
host1

That way if I read off the first host name, process it, rotate it and then put the next host  name at the top to process it.

Yes there is a reason I do not want to just use an array.  Because this affects servers, I want to request to process one, request to process the second, request to process the third.  

thx
0
Comment
Question by:TIMFOX123
  • 2
4 Comments
 

Author Comment

by:TIMFOX123
ID: 38383827
There has to be an awk, sed or perl one liner to do this somewhere !!!
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 1000 total points
ID: 38384101
Try:

perl -ne 'if( $. == 1){$l = $_} else {print;} END{print $l}' filename

Open in new window


If you want to change the file you may do like

perl -i -le 'chomp($l = <>); $/=undef; $f = <>; print $f.$l' filename

Open in new window

0
 
LVL 23

Accepted Solution

by:
savone earned 1000 total points
ID: 38384240
I am not sure what you are trying to do, but if I understand you basically want to loop through a file and use the contents for running commands.

For example, if you wanted to know the IP address for 3 hosts:

for i in `cat filename`; do dig +short $i; done
0
 

Author Closing Comment

by:TIMFOX123
ID: 38388892
thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question