|
V
|
|
ASIC/FPGA Design and Verification Out Source Services
Global file search for text string replace
How to search for files and per each file do a global search of a given text string.
- First do a "find command":
find -type f //all files
find -mtime -2 //two days old
find . -name "*.c" //all c source files
- Than prepare a little bash file including sed command:
#!/bin/bash
sed -e 's/timescale *.SV_TIMESCALE//' $1 > Tmp
\mv -f Tmp $1
- It is possible to create a sed command with multiple replace strings:
sed -e 's/erors/errors/g' -e 's/last/final/g' my_file.txt > Tmp
- To run it just fire up this command:
find . -name "*.v" | xargs -n1 | xargs -i= ./tiRm.unx = where tiRm.unx is the name of the bash file.
- Sometimes only one file is involved. In this case vim can be used to do the conditional replace operation.
:g/0b/s/\([01]\) \(([01]\)/\1\2/g This will remove space between binary [01], if it finds the binary symbol 0b Another example is to replace some annoying ^M, which sometimes appear, when importing files from DOS to unix. :g/ctrlVctrlM/s///g
-
vim replace on blocks:
You can use line numbers or vim marks to define a replace zone area.
12,23g/polarity_cnt/s//polarity_cnt_dbg/g
'a,'b g/polarity_cnt/s//polarity_cnt_dbg/g
where the block is defined by the vim commands ma and mb.
To run a script on a block from vim go to : perl script on run on block form within vim
- Or do it from the command line using perl to do the job of string replace:
perl -i -pe 's/00/99/;' Italian_top_100.txt
- The following script may be helpful, should you need to replace a string in many files:
#!/bin/bash
sed -e 's/replcae me/with this/' $1 > Tmp
#remove empty lines
#sed '/^ *$/d' $1 > Tmp
\mv -f Tmp $1
Note the the script is extremely simple. But its operation is a bit complex:
find . -name "*.c" | xargs -n1 | xargs -i= replace_with_sed_script.unx =
- A similar issue is discussed at: search into multiple files and generate a report The solution in this page uses a for f (similar to perl's foreach statement) and therefore results in a simpler script.
Contact me now at: |
|
... |
|
I would be happy to offer my services. Call ASAP !
|
Search This Site
Feedback This Site
new pages on this site
|
|