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.
Thread Tools Display Modes
Old 18th April 2009, 21: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


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.



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

Thanks in advance

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

Use awk, not sed:

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


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 17:54
The system is currently updating the configuration files. warlock General 8 21st February 2009 19:15
chroot_ssh_sftp_debian_etch jon HOWTO-Related Questions 0 24th August 2008 01:40
Verify email setup meekish Installation/Configuration 28 27th October 2006 16:36
Chrooted SSH apps bkrausz Tips/Tricks/Mods 14 30th August 2006 00:32

All times are GMT +2. The time now is 11:44.

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