CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Find and replace in a file

 



suvendra
New User

Feb 24, 2017, 7:08 PM

Post #1 of 2 (1157 views)
Find and replace in a file Can't Post

i have a file which contains statement as below

cfg_a
cfg_b[2:0]
cfg_c[4:0]
cfg_d

I want to replace them like this using perl
logic cfg_a
logic [2:0] cfg_b
logic [4:0] cfg_c
logic cfg_d

How to do them ?
Please give me a hint


Laurent_R
Veteran / Moderator

Feb 25, 2017, 1:37 AM

Post #2 of 2 (1148 views)
Re: [suvendra] Find and replace in a file [In reply to] Can't Post

Hi,

here's one way to do it with a Perl one-liner:


Code
$ echo 'cfg_a 
cfg_b[2:0]
cfg_c[4:0]
cfg_d ' | perl -ne '($cf, $num) = ($1, $2) if /(cfg_\w+)(\[\d:\d\])*/; print "logic $num $cf\n";
'
logic cfg_a
logic [2:0] cfg_b
logic [4:0] cfg_c
logic cfg_d


Quote

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives