Solved

sed to add "me" at the end of line

Posted on 2000-04-24
3
418 Views
Last Modified: 2013-12-26
Hi,
  I have a text file name file1 in /tmp/file1.  The content of the file
is:
test1 costs
test2 money
test3 deal

I like to use sed to look for test2
and add "me" at the end of the line:

so the output of the file1 above should
be:
test1 costs
test2 money me
test3 deal

thanks in advance
0
Comment
Question by:nngdemi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
dirc earned 50 total points
ID: 2745722
sed -e '/^test2 / {\
s/$/ me/\
}' /tmp/file1 > /tmp/file2
mv /tmp/file2 /tmp/file1

This assumes that test2 is at the beginning of the line and is followed by at least one space.
0
 
LVL 12

Expert Comment

by:tel2
ID: 2746726
nngdemi,

An alternative (but very similar) solution would be:

sed "s/^test2.*/& me/" </tmp/file1 >/tmp/file1.tmp
mv /tmp/file1.tmp /tmp/file1
0
 

Author Comment

by:nngdemi
ID: 2749292
excellent.

Both work.

thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 184
WinWaitActive parameters 12 31
noX challenge 17 143
I could not set window to top 4 61
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question