LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-24-2005, 01:41 PM   #1
ziggie216
Member
 
Registered: Oct 2003
Posts: 176

Rep: Reputation: 30
add word to each line of the file?


If I want to insert a word into the beginning of each line in a file do I use the command "paste"?

from

is a test
is a test2
is a test3


to

this is a test
this is a test2
this is a test3

if so whats the format?
 
Old 04-24-2005, 02:07 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86; Gentoo PPC; Gentoo Sparc64; FreeBSD; OS X; Solaris
Posts: 3,731
Blog Entries: 4

Rep: Reputation: 68
I would use sed instead...
Code:
$ cat file
is a test
is a test2
is a test3
$ cat file | sed -e 's/is/this is/g' >> file2
$ cat file2
this is a test
this is a test2
this is a test3
Paste will combine the lines of two files, separated by a tab.

Last edited by bulliver; 04-24-2005 at 02:10 PM.
 
Old 04-24-2005, 02:45 PM   #3
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 53
Or for the same file "sed -i -e 's/is/this is/' filename"
The "g" would add "this" to all words "is" in a line.
 
Old 04-24-2005, 07:51 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86; Gentoo PPC; Gentoo Sparc64; FreeBSD; OS X; Solaris
Posts: 3,731
Blog Entries: 4

Rep: Reputation: 68
Your right makuyl, good catch...
 
Old 04-25-2005, 04:19 AM   #5
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 45
hi there,

just to contribute:
if your line does not share the same pattern you can use ^
Code:
sed "s/^/this /g" your_file
regards

slackie1000
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
How do you load KDE Add ons like Word galliar Suse/Novell 1 01-27-2005 01:12 PM
word count in a line pantera Programming 4 08-25-2004 01:14 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM
display full line instead of single word in for loop ken734 Linux - Newbie 3 08-15-2003 02:35 PM


All times are GMT -5. The time now is 06:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration