• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

sed to add "me" at the end of line

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
nngdemi
Asked:
nngdemi
1 Solution
 
dircCommented:
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
 
tel2Commented:
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
 
nngdemiAuthor Commented:
excellent.

Both work.

thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now