Search code examples
awksedgrepnotepad

switch the order in a text file


I got a text file in this format:

ip1:user1:pass1
ip2:user2:pass2
ip3:user3:pass3

How can I change the order in lines to get this result?

user1:pass:1@ip1
user2:pass2@ip2
user3:pass3@ip3

Solution

  • awk -F : '{print $2 FS $3 "@" $1}' file
    

    or

    awk 'BEGIN{FS=":"} {print $2 FS $3 "@" $1}' file
    

    or

    awk -F : '{print $2 ":" $3 "@" $1}' file
    

    Output:

    user1:pass1@ip1
    user2:pass2@ip2
    user3:pass3@ip3