Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Adding text to multiple files

$
0
0

I'm trying to update dozens of different files with the same information and then save each individual file out to a different filename.  I'm currently doing this on a UNIX server but need to do it using Powershell.  Here is the the UNIX shell script.

KORLIST=`ls /gadatag/kor/*_t`
for KOR in $KORLIST
do
if [[ -s $KOR ]]
then
sed "s/^/68|/" $KOR  > "$KOR".txt
fi

It takes each file, adds the string '68|' to the beginning of each line of each file and then saves it out to a new filename.  It keeps the orginal file the same.  Here is what I have so far in Powershell.

foreach ($file in dir -Path h:\*_t) {cat $file | %{$_ -replace "^","68|"}}

It does the substitution part right but I can't get it to output to the txt files like in my KornShell script.  I've tried tee-object and out-file but so far no luck.

Any suggestions would be greatly appreciated.  If I need to give futher explanation, please let me know.

Thanks,

Eric


Viewing all articles
Browse latest Browse all 6937

Trending Articles