简体   繁体   中英

Search and delete a block using sed command in ubuntu

The thing I would like to perform is to 1- Find and 2- delete the whole definition block of (__c64):

unsigned long long __c64(unsigned int llvm_cbe_hi, unsigned int llvm_cbe_lo) {
unsigned long long llvm_cbe_retval;    /* Address-exposed local */
unsigned long long llvm_cbe_retval1;



  *(&llvm_cbe_retval) = (((((unsigned long long )(unsigned int )llvm_cbe_hi)) << 32ul) |  (((unsigned          long long )(unsigned int )llvm_cbe_lo)));
  llvm_cbe_retval1 = *(&llvm_cbe_retval);
  return llvm_cbe_retval1;
}

in all but one .c files in a project. Since in the compilation phase of .o to the executable, I got the error "Multiple definition of __c64", I was thinking to delete all of those but one in order to solve the problem.

Any ideas?

Regards,

Amir

If function layout is exactly same in all files you can try this

gvim -p *.c    // Open all relevant files in multiple tabs

then execute this

:bufdo %s/unsigned long long __c64\(.\+\n\)\+\(\n\)\+\(.\+\n\)\+}// | update

"update" executed at the end will save each file.

guys as I found the definitions were dynamically changed, I tried to figure out sth like :

sed '/^unsigned long long __c64/,/}/d'

and it did fortunately work.

Thanks for all the helps.

Amir

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM