Solved

sed to add "me" at the end of line

Posted on 2000-04-24
3
376 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
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 11

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 31
Include multiple hostnames in this command? 3 52
post4 challenge 28 83
matchUp  challenge 9 72
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now