Solved

Inserting into a file

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

628 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