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

Posted on 2012-09-10
Last Modified: 2012-09-11
i have a file


after I process host1,

I want the file to read:


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.  

Question by:TIMFOX123

    Author Comment

    There has to be an awk, sed or perl one liner to do this somewhere !!!
    LVL 31

    Assisted Solution


    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

    LVL 23

    Accepted Solution

    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

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    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…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now