Вопрос

I made a small program that puts line numbers in front of each line in a file! This is working perfectly fine, but their is just one problem. I get this as result:

1

Text one

2

Text two

3

Text three

But I want the output to me like:

1 Text one
2 Text two
3 Text three

I use this code to execute the sed functionality:

char* exec[] = { "sed", "/./=", NULL }; 
execvp(exec[0], exec);

I think I need to change the exec[], but I don't know in what way!

Many thanks :D

Это было полезно?

Решение

sed 'N;N;N;s/\n//g;s/[0-9]*/& /' YourFile

remove \n (base on a structure of 4 line per real line, then add a space after first number

but why using sed to deconstruct what could be done easily construct directly otherwise (cat -n, grep -n, ...) ?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top