Solved

Inserting into a file

Posted on 2007-04-04
1
235 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

757 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

22 Experts available now in Live!

Get 1:1 Help Now