Domanda

I want to prefix/print the string containing the substring as below. Here, substring I mean VIDIOC and the string here i want to log is VIDIOC_S_CTRL as an example

From:

ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
if(ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {

To:

ALOGI("VIDIOC_G_FMT");    ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
ALOGI("VIDIOC_S_CTRL");    if (ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {

I tried to do with sed going through web search, But i could not do. Can anyone please help?

È stato utile?

Soluzione

You could make use of a backreference:

sed '/VIDIO/ s/.*\(VIDIO\w*\)/ALOGI("\1");   &/' inputfile

or

sed -r '/VIDIO/ s/.*(VIDIO\w*)/ALOGI("\1");   &/' inputfile

Altri suggerimenti

gawk-Specific

awk '{match($0,/VIDIO\w*/,a); print "ALOGI(\""a[0]"\");",$0}' input.txt

Output:

ALOGI("VIDIOC_G_FMT"); ret = ioctl(drv_ctx.video_driver_fd, VIDIOC_G_FMT, &fmt);
ALOGI("VIDIOC_S_CTRL"); if(ioctl(drv_ctx.video_driver_fd, VIDIOC_S_CTRL, &control)) {
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top