f



how to make a file from the strings in a file and redirect the content to these new files

Here is scenari0
223 files copied to this this one big flat file.

now how to make this file to 223 files.

further explaination:
below is excerpt from that one file under xxxxx
you will see
@TC_ID: :BIC4007
then another @TC_ID: :BIC40008 and
has a 223 time with TC_ID: :BICxxx numbers

How do I use such a script that makes a file named BIC40008, then
another BIC40007
AND copying the content from line @TC_ID: :BIC40007 till one line
before the next TC_ID: :BIC40008



xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@TC_ID: :BIC40007
@TC_TITLE: 
@ACT_IDS: 
@AUTHOR: 
@AUTO: 
@CLASS: 
@GROUP_ID: 
@RELEASES: 
@TC_DETAILS_FILENAME: 
@BILLING_FILENAME:

@TC_ID: :BIC40008
@TC_TITLE: 
@ACT_IDS: 
@AUTHOR: 
@AUTO: 
@CLASS: 
@GROUP_ID: 
@RELEASES: 
@TC_DETAILS_FILENAME: 
@BILLING_FILENAME: 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I have tried using this script only creating these files
but doesnt go that far
>grep -i TC_ID testcases | cut -c 8-16 | xargs -i touch '{}' .

but just makes only 146 files rather then 223 files

any ideas

thanks
in advance
0
10/7/2004 6:50:39 PM
comp.unix.solaris 26025 articles. 2 followers. Post Follow

4 Replies
1102 Views

Similar Articles

[PageSpeed] 52

"rash" <rashidvoip@yahoo.com> wrote in message news:5bd5ead2.0410071050.2feba65d@posting.google.com...
> Here is scenari0
> 223 files copied to this this one big flat file.
>
> now how to make this file to 223 files.
>
> further explaination:
> below is excerpt from that one file under xxxxx
> you will see
> @TC_ID: :BIC4007
> then another @TC_ID: :BIC40008 and
> has a 223 time with TC_ID: :BICxxx numbers
>
> How do I use such a script that makes a file named BIC40008, then
> another BIC40007
> AND copying the content from line @TC_ID: :BIC40007 till one line
> before the next TC_ID: :BIC40008
>
>
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> @TC_ID: :BIC40007
> @TC_TITLE:
> @ACT_IDS:
> @AUTHOR:
> @AUTO:
> @CLASS:
> @GROUP_ID:
> @RELEASES:
> @TC_DETAILS_FILENAME:
> @BILLING_FILENAME:
>
> @TC_ID: :BIC40008
> @TC_TITLE:
> @ACT_IDS:
> @AUTHOR:
> @AUTO:
> @CLASS:
> @GROUP_ID:
> @RELEASES:
> @TC_DETAILS_FILENAME:
> @BILLING_FILENAME:
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> I have tried using this script only creating these files
> but doesnt go that far
> >grep -i TC_ID testcases | cut -c 8-16 | xargs -i touch '{}' .
>
> but just makes only 146 files rather then 223 files
>
> any ideas
>

Probably best to use awk or perl, both of which have their
own newsgroups.

Here is an awk script to do what you want:

        BEGIN { FS = ":" }
        $1 == "@TC_ID" { file = $3 }
        NF > 0 { print >> file }
        NF == 0 { close(file) }

Save it in a file called (say) filesplitter and use it as:
    awk -f filesplitter your_one_big_flat_file

The first line sets the field separator (FS) to colon (:).
The second line sets file to be the third field ($3) of
any line whose first field ($1) is "@TC_ID". (Note == not = .)
The third line prints any line with more than one field to file.
The fourth line closes file on encountering a blank line.

HTH.

-- 
John.


0
John
10/7/2004 7:41:48 PM

rash wrote:
> Here is scenari0
> 223 files copied to this this one big flat file.
> 
> now how to make this file to 223 files.
> 
> further explaination:
> below is excerpt from that one file under xxxxx
> you will see
> @TC_ID: :BIC4007
> then another @TC_ID: :BIC40008 and
> has a 223 time with TC_ID: :BICxxx numbers
> 
> How do I use such a script that makes a file named BIC40008, then
> another BIC40007
> AND copying the content from line @TC_ID: :BIC40007 till one line
> before the next TC_ID: :BIC40008

This should do it:

gawk -vRS="@TC_ID: :" 'NR>1{printf "%s%s",RS,$0 > $1}' input

Regards,

	Ed.
0
Ed
10/7/2004 10:53:45 PM
rashidvoip@yahoo.com (rash) wrote in message news:

>
> Here is scenari0
> 223 files copied to this this one big flat file.
> 
> now how to make this file to 223 files.
> 
> further explaination:
> below is excerpt from that one file under xxxxx
> you will see
> @TC_ID: :BIC4007
> then another @TC_ID: :BIC40008 and
> has a 223 time with TC_ID: :BICxxx numbers
> 
> How do I use such a script that makes a file named BIC40008, then
> another BIC40007
> AND copying the content from line @TC_ID: :BIC40007 till one line
> before the next TC_ID: :BIC40008
> 

The right tool for this scenario is 'csplit' aka "context split"
and preferably from the GNU stable:
  
  csplit -f BIC40 your_large_inp_file '/@TC_ID: :/' '{*}'
0
sharma__r
10/8/2004 6:16:39 AM
gawk -vRS="@TC_ID: :" 'NR>1{printf "%s%s",RS,$0 > $1}' input


This above command worked 
EXCELLENT
and csplit is little complicated for me

thank you guys

Rash

Ed Morton <morton@lsupcaemnt.com> wrote in message news:<ck4hdr$2t7@netnews.proxy.lucent.com>...
> rash wrote:
> > Here is scenari0
> > 223 files copied to this this one big flat file.
> > 
> > now how to make this file to 223 files.
> > 
> > further explaination:
> > below is excerpt from that one file under xxxxx
> > you will see
> > @TC_ID: :BIC4007
> > then another @TC_ID: :BIC40008 and
> > has a 223 time with TC_ID: :BICxxx numbers
> > 
> > How do I use such a script that makes a file named BIC40008, then
> > another BIC40007
> > AND copying the content from line @TC_ID: :BIC40007 till one line
> > before the next TC_ID: :BIC40008
> 
> This should do it:
> 
> gawk -vRS="@TC_ID: :" 'NR>1{printf "%s%s",RS,$0 > $1}' input
> 
> Regards,
> 
> 	Ed.
0
rashidvoip
10/8/2004 5:23:11 PM
Reply: