how to make a file from the strings in a file and redirect the content to these new fi
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > how to make a file from the strings in a file and redirect the content to these new fi




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-07-04 10:49 PM

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:

 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx

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





[ Post a follow-up to this message ]



    Re: how to make a file from the strings in a file and redirect the content to these ne  
John L


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-07-04 10:49 PM


"rash" <rashidvoip@yahoo.com> wrote in message news:5bd5ead2.0410071050.2feba65d@posting.goo
gle.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:
>
>  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx
>
> I have tried using this script only creating these files
> but doesnt go that far 
>
> 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.







[ Post a follow-up to this message ]



    Re: how to make a file from the strings in a file and redirect the content to these ne  
Robert Bonomi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-07-04 10:49 PM

In article <5bd5ead2.0410071050.2feba65d@posting.google.com>,
rash <rashidvoip@yahoo.com> 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

*IF* the 'sections' are all exactly the same number of lines, then
'man split'.

Otherwise, this is an 'awkward' job, thus _awk_ is right tool.

1) when the string ^@TC_ID: is matched, extract the 2nd 'word' on the
line, and save it for use as the output file name.
2) for each line, print to a file named with the saved value.

housekeeping, when you change the output file name, you will probably
need to close previously open output file, to avoid exhausting file handles.

>
>
>
>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:
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxx
>
>I have tried using this script only creating these files
>but doesnt go that far 
>
>but just makes only 146 files rather then 223 files
>
>any ideas
>
>thanks
>in advance







[ Post a follow-up to this message ]



    Re: how to make a file from the strings in a file and redirect the content to these ne  
rakesh sharma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-08-04 07:47 AM

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: :/' '{*}'





[ Post a follow-up to this message ]



    Re: how to make a file from the strings in a file and redirect the content to these ne  
rash


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-08-04 10:52 PM

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: 
>
> This should do it:
>
> gawk -vRS="@TC_ID: :" 'NR>1{printf "%s%s",RS,$0 > $1}' input
>
> Regards,
>
> 	Ed.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:28 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register