views:

126

answers:

4

I was hoping someone could help me, I need to reverse the contents of each line in a file. So basically this: 101.228.168.192 to 192.168.228.101 Is there a command I could use in a bash script, or even just the logic needed to get the job done. Thanks

+6  A: 

You could use awk:

awk -F'.' '{print $4"."$3"."$2"."$1}' file.txt > output.txt
Mark Byers
Thanks, that did exactly what I needed.
Brimak
+4  A: 
perl -nl -e 'print join(".", reverse( split /\./ ))' filename.txt
runrig
Thank you, I tried your method, and it does what I needed as well
Brimak
+3  A: 
 sed 's/\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)/\4.\3.\2.\1/g' filename.txt

thanks for the comment Sean

Levon Mirzoyan
A: 

A bash solution

while IFS="." read -r A B C D; do
  echo "$D.$C.$B.$A"
done < file