Renaming files and replacing strings in them

How many times did you have the task of creating a new UVC or testbench based on the old one?

The task is simple:

Rename all the files in all relevant directories and then replace some strings in all of them.

Yet, I’ve seen more than once people using an ‘mv’ command to rename each file, open it in an editor and perform search-and-replace.

Instead, you can you two simple and extremely useful commands:

  1. rename

rename

Example:

rename uvc1 uvc2 source/sv/*.sv

This will rename all files that have ‘uvc1’ in their name to contain ‘uvc2’ instead

For example vtool_uvc1_slave_driver.sv will be renamed to vtool_uvc2_slave_driver.sv

  1. sed

The sed command can do many things. In its most basic form it can simply search and replace:

sed -i ‘s/ahb/axi/g’ source/sv/*.sv

This will search and replace the string ‘ahb’ with ‘axi’ in all the provided files.

Check out some complex examples in:

https://linuxhint.com/50_sed_command_examples/

Most importantly, never settle for tedious manual work. Automate!

Contact Us

Please, enter your details below. We will get back to you as fast as we can.

This website uses cookies to ensure you get the best experience on our website.

Get Cogita

Please, enter your details below. We will get back to you as fast as we can.

Thank you!

We will get in touch soon.

Get a Quote

Please, enter your details below. We will get back to you as fast as we can.