in reply to Reaped: To find and replace in a file
http://www.perlmonks.org/?node=Tutorials#Pattern-Matching-Regular-Expressions-and-Parsing may be of interest to you.#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; $_ = "$2 $1" if ( /^(.+)(\[.+)/ ); #swaps 2 pieces if both found print "logic $_\n"; } =Prints logic cfg_a logic [2:0] cfg_b logic [4:0] cfg_c logic cfg_d =cut __DATA__ cfg_a cfg_b[2:0] cfg_c[4:0] cfg_d
|
|---|