The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
copy files from one location to similar location pharos467 UNIX for Advanced & Expert Users 1 09-21-2008 01:21 PM
Need Help for Adding Three new columns in existing file from fatching data from file Sandeep_Malik Shell Programming and Scripting 36 09-17-2008 06:12 PM
adding data behind a line cherrywinter Shell Programming and Scripting 1 08-01-2008 06:55 PM
What is the file location? Chanakya.m Shell Programming and Scripting 5 07-17-2006 01:42 AM
Adding files of numerical data Boucho High Level Programming 17 02-07-2006 04:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2008
divya_flora divya_flora is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 2
adding the data at a specified location in a file....

Hi all,
I m new to shell programming..Can anyone please guide me how to insert data at a specified location in the file..
I have a configuration file..I want to add data to it through script..I am able to do it...I get that data written at end of my configuration file..I want data to be placed at a specified location...
As,I have a header [mydata] in my configuration file..I want to place the data here...
Is it possible to do that...
Example:
My configuration file:
[global]
hello
aaa
bbbb
[share]
gghg
hnnmm
bbb
[mydata]
gggg
[printing]
cvbvbb
vbvbb
Now,I want my data to be entered after header [mydata], not at the end of Configuration file...

Thanking you...
  #2 (permalink)  
Old 10-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,350
Try this:

Code:
awk -v dat="Yourdata" '/\[share\]/{print;print dat;next}1' file > newfile

Regards
  #3 (permalink)  
Old 10-24-2008
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,323

Code:
sed '/\[mydata\]/a\all i ever wanted\nall i ever needed\nis here in my arms' infile
[global]
hello
aaa
bbbb
[share]
gghg
hnnmm
bbb
[mydata]
all i ever wanted
all i ever needed
is here in my arms
gggg
[printing]
cvbvbb
vbvbb

  #4 (permalink)  
Old 10-24-2008
divya_flora divya_flora is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 2
Hi,
Thanks so much..This has helped me to understand the concept...
Actually,This is my script which inserts the data into the configuration file..

#!/bin/bash
CF="/etc/samba/smb-test.conf" //Configuration file
.....................
...............

insert_mod() { //Function to insert data into config file
NCF="$CF.$$"
[ ! -f $CF ] && touch $CF || :
V="$1"
grep -v -E "^$V=" $CF > $NCF
mv -f $NCF $CF
eval echo "$V\"'\${$V}'\"">> $CF

}
hello=yes
insert_mod hello //Function called with argument
else
illegal
fi

...............
SO,HOW CAN I USE sed COMMAND HERE....

Thanking you in advance...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0