LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How could i add to the beginning of line word? (https://www.linuxquestions.org/questions/programming-9/how-could-i-add-to-the-beginning-of-line-word-670412/)

DoME69 09-17-2008 12:54 AM

How could i add to the beginning of line word?
 
Hi i whould like to add different word of each line

Example:

bla bla bla fast
bla bla bla slow bla
bla bla typical bla bla

the result should be...

kuku1 bla bla bla fast
kuku2 bla bla bla slow bla
kuku3 bla bla typical bla bla

Thanks.

burschik 09-17-2008 01:06 AM

Maybe you should concentrate more on describing what you want to achieve and less on "bla bla bla". Assuming that you want to insert a fixed string followed by the line number, you could try

Code:

awk '{print "kuku" NR $0;}'

Mr. C. 09-17-2008 01:09 AM

or ...

sed 's/^/kuku1 /'


i'm tired - this solution doesn't solve the problem. Sorry.

chrism01 09-17-2008 01:11 AM

Code:

IFS="
"
num=0
for rec in `cat t.t`
do
    num=$(( $num + 1 ))
    echo "kuku${num} $rec" >>t1.t
done

is one soln

DoME69 09-17-2008 01:52 AM

...
 
what i mean is when the word fast show i want at the first line the word kuku1

Example:

bla bla bla fast
bla bla bla slow bla
bla bla typical bla bla
bla bla slow
bla typical bla bla bla
the result should be...

kuku1 bla bla bla fast
kuku2 bla bla bla slow bla
kuku3 bla bla typical bla bla
kuku2 bla bla slow
kuku3 typical bla bla bla

Thanks.

burschik 09-17-2008 02:27 AM

And that is, of course, something entirely different. Basically:

Code:

sed '/fast/ s/^/kuku1 /; /slow/ s/^/kuku2 /;'
And so on.

DoME69 09-17-2008 02:55 AM

Quote:

Originally Posted by burschik (Post 3282800)
And that is, of course, something entirely different. Basically:

Code:

sed '/fast/ s/^/kuku1 /; /slow/ s/^/kuku2 /;'
And so on.

Thanks a lot. :)


All times are GMT -5. The time now is 05:31 AM.