在 linux 如何替换文件中模式内的子模式
In linux how to replace a sub pattern inside a pattern in a file
我想更改一个文件,read_write.c的内容
SYSCALL_DEFINE1(lchown, const char __user *, filename, uid_t, user)
SYSCALL_DEFINE2(open, const char __user *, filename, int)
到
SYSCALL_DEFINE1(lchown, const char __user *, filename, uid_t, user)
SYSCALL_DEFINE2(open, const unsigned char __user*, filename, int)
即我只想更改 SYSCALL_DEFINE2
内的参数,而不是 SYSCALL_DEFINE1
内的参数
使用 GNU sed:
sed '/SYSCALL_DEFINE2(/,/)/{s/const char __user \*/const unsigned char __user\*/}' file
从包含 SYSCALL_DEFINE2(
的行到包含 )
的行,这会将 const char __user *
替换为 const unsigned char __user*
。
输出:
SYSCALL_DEFINE1(lchown, const char __user *, filename, uid_t, user)
SYSCALL_DEFINE2(open, const unsigned char __user*, filename, int)
查看 man sed
并搜索 addresses
。
我想更改一个文件,read_write.c的内容
SYSCALL_DEFINE1(lchown, const char __user *, filename, uid_t, user)
SYSCALL_DEFINE2(open, const char __user *, filename, int)
到
SYSCALL_DEFINE1(lchown, const char __user *, filename, uid_t, user)
SYSCALL_DEFINE2(open, const unsigned char __user*, filename, int)
即我只想更改 SYSCALL_DEFINE2
内的参数,而不是 SYSCALL_DEFINE1
使用 GNU sed:
sed '/SYSCALL_DEFINE2(/,/)/{s/const char __user \*/const unsigned char __user\*/}' file
从包含 SYSCALL_DEFINE2(
的行到包含 )
的行,这会将 const char __user *
替换为 const unsigned char __user*
。
输出:
SYSCALL_DEFINE1(lchown, const char __user *, filename, uid_t, user) SYSCALL_DEFINE2(open, const unsigned char __user*, filename, int)
查看 man sed
并搜索 addresses
。