如果你有 vim 可用,你可以将以下命令保存在一个文件中。
1,$s/sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
wa
q
我们将文件命名为 temp.vim。
你可以执行:
vim -S temp.vim <filename>
更新文件。
s命令解释:
1,$s/sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
1,$s -> substitue in all the lines of the file
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ ---- The pattern to subtitute ------- ^
^ -- substitution -- ^
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ ^ -> Ignore everthing up to and including the second < after sc_fifo_in.
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ ^ -> Capture everything up to the next , (data_type)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ ^ -> Capture everything up to the next , (WIDTH)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ ^ -> Capture everything up to the next > (HEIGHT)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ ^ -> Capture everything up to ; (in)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ The data type (the first capture)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ The variable name (the fourth capture)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ WIDTH (the second capture)
sc_fifo_in<[^<]*<\([^,]*\),\s*\([^,]*\),\s*\([^>]*\)>\s*>\s\([^;]*\);/sc_fifo_in<\1> \4[\2 * \3];/ge
^ HEIGHT (the third capture)