Solved

Inserting into a file

Posted on 2007-04-04
1
252 Views
Last Modified: 2010-04-21
Hi,
I have a file which looks something like

#group1{
a
b
c
d}

#group2{
a
d
1
2
3
}

#group3{
x
y
u
}

Im trying to insert into this file a line under a specified group (or #groupx{ ). So if i say insert g into group2 it will turn the file into:


#group1{
a
b
c
d
#group1}

#group2{
g
a
d
1
2
3
#group2}

#group3{
x
y
u
#group3}

what Im looking for is a way of doing this in a single line. Can anyone help me with this?
Thanks!
0
Comment
Question by:Traltixx
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 18855874
perl -i -pe '$_.="g\n" if /#group2\{/' file
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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

685 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