Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 18th April 2009, 20:11
mangecelle mangecelle is offline
Junior Member
 
Join Date: Oct 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create text files dynamically from master textfile with sed

Hi,

I am trying to accomplish the following task with help of bash scripting. From a programming tool i use i can export objects to a text file. They can be exported separetely or together. The programming tool generates for me one text file with the diferent objects exported as text. The structure is the following.


OBJECT Table 3 Table name
{
object properties
}


OBJECT Table 4 Table name
{
object properties
}


OBJECT Form 10 Form name
{
object properties
}


As you can see there can be different object types e.g. Table/Form/Codeunit etc.

I would like to send this file to a script and have that script to generate separete files for me. The files should be named according to the object type. "Object Type"_"number".txt. So in the example above the script should generate 3 files named: Table_3.txt, Table_4.txt and Form_10.txt.

I have been looking at for example sed to help me accomplish this. But i am stucked and donīt know how to proceede. I have looked in to the sed manual. There is a way to match a start and an end caracter.

Code:
#!/bin/bash

FileName=$1

for object in $(sed -n -e '/^OBJECT Table/,/^}/p' $FileName)
do
  ... do stuff here
done
With this code how can i now that one start/end cycle has finished?

Thanks in advance

Mange
Reply With Quote
Sponsored Links
  #2  
Old 21st April 2009, 04:16
cfajohnson cfajohnson is offline
Junior Member
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

Use awk, not sed:

Code:
awk '
   BEGIN  { filename = "/dev/null" }
/^OBJECT/ { filename = $2 "_" $3 }
          { print > filename }
' "$FILE"
Reply With Quote
Reply

Bookmarks

Tags
sed textfile create

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54
The system is currently updating the configuration files. warlock General 8 21st February 2009 18:15
chroot_ssh_sftp_debian_etch jon HOWTO-Related Questions 0 24th August 2008 00:40
Verify email setup meekish Installation/Configuration 28 27th October 2006 15:36
Chrooted SSH apps bkrausz Tips/Tricks/Mods 14 29th August 2006 23:32


All times are GMT +2. The time now is 07:03.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.