LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2008, 12:54 AM   #1
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Rep: Reputation: 16
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.
 
Old 09-17-2008, 01:06 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
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;}'
 
Old 09-17-2008, 01:09 AM   #3
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
or ...

sed 's/^/kuku1 /'


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

Last edited by Mr. C.; 09-17-2008 at 01:32 AM.
 
Old 09-17-2008, 01:11 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
IFS="
"
num=0
for rec in `cat t.t`
do
    num=$(( $num + 1 ))
    echo "kuku${num} $rec" >>t1.t
done
is one soln
 
Old 09-17-2008, 01:52 AM   #5
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
...

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.
 
Old 09-17-2008, 02:27 AM   #6
burschik
Member
 
Registered: Jul 2008
Posts: 159

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

Code:
sed '/fast/ s/^/kuku1 /; /slow/ s/^/kuku2 /;'
And so on.
 
Old 09-17-2008, 02:55 AM   #7
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by burschik View Post
And that is, of course, something entirely different. Basically:

Code:
sed '/fast/ s/^/kuku1 /; /slow/ s/^/kuku2 /;'
And so on.
Thanks a lot.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed insert # at the beginning of a line ilo Linux - Newbie 17 12-19-2012 08:21 AM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 08:33 AM
add word to each line of the file? ziggie216 Linux - General 4 04-25-2005 04:19 AM
How to add data at file beginning in C? Nad0xFF Programming 8 04-17-2005 11:48 AM
deleting characters at the beginning of a line poobeany Programming 6 09-23-2003 05:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration