开发者

Reverse the contents of each line in a file?

I was hoping someone could help me, I need to reverse the contents of each line in a file. So basi开发者_如何学编程cally 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


You could use awk:

awk -F'.' '{print $4"."$3"."$2"."$1}' file.txt > output.txt


perl -nl -e 'print join(".", reverse( split /\./ ))' filename.txt


 sed 's/\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)/\4.\3.\2.\1/g' filename.txt

thanks for the comment Sean


A bash solution

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜