Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Convert bash or powershell to AutoIT

$
0
0
I really want to use AutoIT to perform a search for lines beginning with a string and then replace the whole line with a substitute. (quickly for an entire file)

In powershell I do it like this:
$ComputerName = $env:COMPUTERNAME
$FilePath = "C:\scripts\data.txt"
$FindIT = "WorkstationID"
$ReplaceIT = ("WorkstationID=" + $ComputerName + "stuff")
#"----------------------"
(Get-Content ($FilePath)) |
Foreach-Object { $_ -replace ('^' + $FindIT + '.*$'), $ReplaceIT } |
Set-Content  ($FilePath)

"cat the file to screen to see changes"
"-----------------------------------------------"
Get-Content ($FilePath) | foreach {Write-Output $_}



in bash I do it like this, yes it's Linux but I need to do this type of thing in Windows:
swap()
#------------------------ swap function ------------------------------------------
# this little function is for a find and replace of lines starting with a string
# first parameter is the file to be modified
# second parameter is the line that begins with the string provided (all occurances)
# third parameter is the entire line of data to insert in the place of second parameter
{
#echo first command line parameter (file name) is "$1"
#echo second parameter (search for) is  "$2"
#echo third parameter (replace string) is "$3"
if [ ! -f $1 ]
then
  echo "A find and replace command was attempted against $1 but the file could not be found!"
  return
else
  mv $1 $1"-temp1"
  varFind="$2"
  varReplace="$3"
  cat $1"-temp1" | sed -e "s,^$varFind.*,$varReplace,g" >> $1
  rm -f $1"-temp1"
  echo "Modified $1 with $3"
fi
};
#-------------- end swap ------------------------------------------------------


How do I do this in AutoIT?

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>