Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

can i preprocess text for ssis?

Closed Thread
 
Thread Tools Display Modes
Old 12-27-2007   #1 (permalink)
drew
Guest


 

can i preprocess text for ssis?

as background, i have a conditional split transform in front of several
derived columns, the condition is based on what characters appear at position
60 in each line. this was needed because the state changed the file format,
but the files are all stored in a shared way, we cant move or change them.
there are 440 files of several hundred thousand lines, so inspection is not
a possibiltiy, the spec was fine for spelling out the 'switch' characters for
most of the files, but we'd like to do kind of a select distinct to show each
character at position sixty for each line in each file, so we are sure that
the conditional split transform has accounted for all the switch characters,
because we suspect that there are other characters in that position that we
need to trap, (they dont error, but they dont find a home in the distribution
either) but dont want to sort though all the text files to find the unknown
character(s) at position sixty.

the other thing is related, but on different text files from the unix side
of the house, to be able to insert a CRLF at position 1201 in a file that has
no line feeds, it just one giant line, so we can chop it into 1200 byte size
lines each. i am sick of them telling me to open it in wordpad to fix it, and
that gets old fast too.
i have no idea how to go about doing these two jobs, but they would really
move the rock.
thanks very much
drew
Old 12-27-2007   #2 (permalink)
Marco Shaw [MVP]
Guest


 

Re: can i preprocess text for ssis?

Quote:

> the other thing is related, but on different text files from the unix side
> of the house, to be able to insert a CRLF at position 1201 in a file that has
> no line feeds, it just one giant line, so we can chop it into 1200 byte size
> lines each. i am sick of them telling me to open it in wordpad to fix it, and
> that gets old fast too.
> i have no idea how to go about doing these two jobs, but they would really
> move the rock.
Does this work for you for your 2nd question?

#Get the contents of the file
$string=get-content test.txt
#Loop here, start with $i=0, and increment by 4.
#You'd do perhaps $jump=1200
#And stop and the end.
$jump=4
for($i=0;$i -lt $string.length;$i=$i+$jump)
{
#Get the substring, after moving up
#to the current $i position, and getting
#the next $jump characters.
$cur=$string.substring($i,$jump)
#Echo out
$cur
#Or write to a file, but uncomment
#$cur|add-content -path test1.txt
}


--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
Old 12-27-2007   #3 (permalink)
Hal Rottenberg
Guest


 

Re: can i preprocess text for ssis?

Hal Rottenberg wrote:
Quote:

> The 1201 thing:
>
> Get-Content unixfile.txt | % { $_.Insert(1200, "`n") }
And pipe to set-content to create a new file.

Get-Content unixfile.txt | % { $_.Insert(1200, "`n") } |
set-content dosfile.txt



--
Hal Rottenberg <hal@xxxxxx>
Author, TechProsaic (http://halr9000.com)
Webmaster, Psi (http://psi-im.org)
Co-host, PowerScripting Podcast (http://powerscripting.net)
Old 01-03-2008   #4 (permalink)
drew
Guest


 

Re: can i preprocess text for ssis?

Hi
In working through this, (after making the changes to 1200 and add-content)
i get an error that says [System.Object[]] does not contain a method called
substring at 14:26.
What is peculiar is that it worked the first time as you wrote it ($jump = 4
writing to the console) but this error materialzed when I set $jump=1200 and
wrote it to a file.

thanks very much for bearing with me, using it is the only way to learn it!
drew


"Marco Shaw [MVP]" wrote:
Quote:

>
Quote:

> > the other thing is related, but on different text files from the unix side
> > of the house, to be able to insert a CRLF at position 1201 in a file that has
> > no line feeds, it just one giant line, so we can chop it into 1200 byte size
> > lines each. i am sick of them telling me to open it in wordpad to fix it, and
> > that gets old fast too.
> > i have no idea how to go about doing these two jobs, but they would really
> > move the rock.
>
> Does this work for you for your 2nd question?
>
> #Get the contents of the file
> $string=get-content test.txt
> #Loop here, start with $i=0, and increment by 4.
> #You'd do perhaps $jump=1200
> #And stop and the end.
> $jump=4
> for($i=0;$i -lt $string.length;$i=$i+$jump)
> {
> #Get the substring, after moving up
> #to the current $i position, and getting
> #the next $jump characters.
> $cur=$string.substring($i,$jump)
> #Echo out
> $cur
> #Or write to a file, but uncomment
> #$cur|add-content -path test1.txt
> }
>
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
>
Old 01-04-2008   #5 (permalink)
Marco Shaw [MVP]
Guest


 

Re: can i preprocess text for ssis?

drew wrote:
Quote:

> Hi
> In working through this, (after making the changes to 1200 and add-content)
> i get an error that says [System.Object[]] does not contain a method called
> substring at 14:26.
> What is peculiar is that it worked the first time as you wrote it ($jump = 4
> writing to the console) but this error materialzed when I set $jump=1200 and
> wrote it to a file.
>
> thanks very much for bearing with me, using it is the only way to learn it!
> drew
Does the file contain sensitive data? Maybe you could send me a copy?

marco DOT shaw AT gmail DOT com
Old 01-07-2008   #6 (permalink)
Marco Shaw [MVP]
Guest


 

Re: can i preprocess text for ssis?

Marco Shaw [MVP] wrote:
Quote:

>
Quote:

>> the other thing is related, but on different text files from the unix
>> side of the house, to be able to insert a CRLF at position 1201 in a
>> file that has no line feeds, it just one giant line, so we can chop it
>> into 1200 byte size lines each. i am sick of them telling me to open
>> it in wordpad to fix it, and that gets old fast too.
>> i have no idea how to go about doing these two jobs, but they would
>> really move the rock.
The thing Hal and I didn't think of is that your original file, is a
single line.

get-content always seems to produce an array, by default. So if you
have a single line, get-content is giving you an array object. The
array object doesn't have a insert or substring method.

You have to specifically cast to a string:

[string]$content=get-content my_one_liner_file

Then, you have the string methods available for $content.


--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing text on multiple text files chufa72 VB Script 13 3 Weeks Ago 03:52 PM
MVP's, text to speech!!, Can I dictate in other text input program andy t Vista General 0 07-15-2008 02:58 PM
Howto: Add lines of text from a specific point in a text file.. Daz VB Script 13 06-24-2008 10:55 AM
SSIS - string variable! Daniel .NET General 0 05-15-2008 05:53 AM
How do I read a text file and sort text by fixed positions? Cornelius PowerShell 5 07-20-2007 06:34 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50