Solved

Inserting into a file

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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…
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.

734 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