Issue Within my dbt scripts I need to run a few SQL commands that don’t need to feed into something else (for example db cloning, permission setting, etc). How can I improve the performance of running multiple little queries? Solution
Continue readingTag: scripting
How can I reliably discover the full path of the Ruby executable?
Issue I want to write a script, to be packaged into a gem, which will modify its parameters and then exec a new ruby process with the modified params. In other words, something similar to a shell script which modifies
Continue readingHow to extract, rename and view some log files from user inputed tar filename?
Issue The problem is like this : I need to extract the logs from a tar archive using user input/argument for the file name (cubelog_457890.tar) In the archive there is just one folder named tftpboot that I need to rename
Continue readinghow to insert line break after a specific string?
Issue I have a file with the following text, I want to make a line break, after the S. character i have this 1900-01-01 00:00:00|1|S|S|S|S.1900-01-01|S.1900-01-01 00:00:00|1|S|S|S|S.1900-01-01 00:00:00|1|S|S|S|S. i want 1900-01-01 00:00:00|1|S|S|S|S. 1900-01-01|S. 1900-01-01 00:00:00|1|S|S|S|S. 1900-01-01 00:00:00|1|S|S|S|S. i tried this $
Continue readingPoweshell alias for startTIME of Process
Issue I am trying to create a simple powershell script which will allow it to display the PID and the starttime of a process. For the moment this is my code –> $proc=$args[0] if (get-process -name $proc -ErrorAction SilentlyContinue) {
Continue readingInteractive CLI packages – checkboxes & selection
Issue I am trying to learn more about making some cool CLI interfaces to provide the options for some local scripts. By digging into the source of the yeoman-generator I was able to come across inquirer for Node, which is
Continue readingWhy does shellcheck fail when a source file is representing the variables at the top of a script?
Issue Ubuntu 16.04 Bash 4.3.48 Why does shellcheck fail when a source file is representing the $variables at the top of a script? Here is a simple script: #!/bin/bash . .sourcefile echo “Today is ${day}.” Here is my source file:
Continue readingsed/awk to insert txt from one file into another file at a particular point
Issue I am attempting to add configuration to an xml file inside docker (which I believe is unimportant) I have the configuration pieces I want to insert into the xml file in another file. The configuration file looks a little
Continue readingCheck if a string matches a regex in Bash script
Issue One of the arguments that my script receives is a date in the following format: yyyymmdd. I want to check if I get a valid date as an input. How can I do this? I am trying to use
Continue readingInfinite 'for' loop with Bash
Issue I have a script like #!/bin/bash for i in {1..xx};do break="$i" If….; then Some command else break;fi done I need something which can repeat this script n times with incrementing $i. I tried this: For (( ; ; ));
Continue readingWhat is the best scripting language to embed in a C# desktop application?
Issue We are writing a complex rich desktop application and need to offer flexibility in reporting formats so we thought we would just expose our object model to a scripting langauge. Time was when that meant VBA (which is still
Continue readingHow can I output Results from command to textbox
Issue Reposting with entire code. This works fine but I want want the username to be output to $User not Out-GridView. The rest of the form relies on the information in the textboe $User I am sure this is something
Continue readingBash error: Division on zero error when using directory path
Issue I’m writing a bash script that checks the number of files in a directory and if it’s over a certain number, do something. The code is here: DIR=/home/inventory waiting=”$((ls ${DIR}/waiting/ -1 | wc -l))” echo $waiting if [ $waiting
Continue readingScript for .SAT (ACIS) files manipulation
Issue I need to make a script for ACIS files manipulation, for example: I have 1 SAT file exported from a CAD software with a 3D Model, and i want to create a script in some language (php, python, etc..
Continue readingHow can I filter out text twice in Powershell?
Issue I have a Powershell script that returned an output that’s close to what I want, however there are a few lines and HTML-style tags I need to remove. I already have the following code to filter out: get-content “atxtfile.txt”
Continue readingHow to set the process name of a shell script?
Issue Is there any way to set the process name of a shell script? This is needed for killing this script with the killall command. Solution Here’s a way to do it, it is a hack/workaround but it works pretty
Continue readingShell to run StreamSets Pipeline
Issue I want to connect to the Control Hub and want to run the particular StreamSets pipeline using Shell Script. Solution In the StreamSets Control Hub web UI, click on RESTful API and then Job Runner. You will see instructions
Continue readingBigQuery: JOIN on single matching row
Issue I have two tables, one containing orders with a nested line_items structure and another with a pricing history for each product sku code. Orders Table order_id order_date item_sku item_quantity item_subtotal 1 2022-23-07 SKU1 7 12.34 SKU2 1 9.99 2
Continue readingFile name too long bash
Issue i want to copy some files from ../soft to ../copu_new. The name of that tests are in ../sim/soft.txt. I had en error : cp:cannot stat ‘../soft/file1.txt\file2.txt\file3.txt’: File too long Follow the code below: input="../sim/soft.txt" while read line do ##to
Continue readingFile name too long bash
Issue i want to copy some files from ../soft to ../copu_new. The name of that tests are in ../sim/soft.txt. I had en error : cp:cannot stat ‘../soft/file1.txt\file2.txt\file3.txt’: File too long Follow the code below: input="../sim/soft.txt" while read line do ##to
Continue readingScripting with gnuplot–where sed
Issue So I’m looking for some quick-and-dirty solution. The problem: I am trying to plot a specific section of a data file with gnuplot. This is fine. The basic line goes something like plot “<(sed -n ‘1,100p’ pointsandstuff.dat)” u 1:log($4**2+$5**2)
Continue readingGet list of git repo branch names
Issue How do I get a list of branch names from a git repository in a shell script? e.g. If my repo has the following branches: master, dev, test, feature/new-feature I want to store these in a list that can
Continue readingAWS Lambda unzips and returns file to s3 bucket — issue with dropped zip file folder name
Issue I have been having some issues with my aws lambda that unzips a file inside of our s3 bucket. I created a script that would activate from a json payload that gets those passed through to it. The problem
Continue readingFinding lines in first file not in the second file based on column
Issue I have two files like these: file1: A;B C;D E;F file2: D F I want to find the lines in file1 that the second column is not in file2. For this example, the desired result is: A;B I tried
Continue readingHow to return multiple variables from python to bash
Issue I have a bash script that calls a python script. At first I was just returning one variable and that is fine, but now I was told to return two variables and I was wondering if there is a
Continue readingPython for Maya, solar system generator
Issue The end goal is to create a solar system that is semi-randomly generated, using polySphere and Curves, assigning colours, etc. Right now I’ve got the background size (a polyPlane with four different options in an optionsMenu) sorted out, and
Continue readingWhich to choose on Windows: VBScript, JScript, Wscript
Issue I need to write some scripts for WinXP to support some of the analysts here at Big Financial Corp. I need to decide which type of Windows scripting best fits my needs. My needs seem pretty simple (to me
Continue readingBulk modification of unique ids in SQL Server
Issue [This is a bit of an unusual problem, I know…] What I need is a script that will change every unique id value to new one in our database. The problem is that we have configuration tables that can
Continue readingWait for bash background jobs in script to be finished
Issue To maximize CPU usage (I run things on a Debian Lenny in EC2) I have a simple script to launch jobs in parallel: #!/bin/bash for i in apache-200901*.log; do echo "Processing $i …"; do_something_important; done & for i in
Continue readingHow to use text file variables in bash script
Issue I have a variable text file, in which All of my variables are there. I wrote a script through which I get the content of the file, here’s the script: #!/bin/sh value=`cat dev.txt` echo "$value" And I got this
Continue readingRunning MySQL *.sql files in PHP
Issue I have two *.sql files that I use when creating a new web site database. The first file creates all the tables. The second file populates some default records. I would like to execute these files from PHP. I
Continue readingLoading .sql files from within PHP
Issue I’m creating an installation script for an application that I’m developing and need to create databases dynamically from within PHP. I’ve got it to create the database but now I need to load in several .sql files. I had
Continue readingObfuscate file name and folder path
Issue I am working on a git repo and I need to share folder hierarchy and file names to external vendor to perform some code analysis. I have whole hierarchy available in a csv file. Problem is that I cannot
Continue readingStopping scripters from slamming your website
Issue I’ve accepted an answer, but sadly, I believe we’re stuck with our original worst case scenario: CAPTCHA everyone on purchase attempts of the crap. Short explanation: caching / web farms make it impossible to track hits, and any workaround
Continue readingHow to add an option to a command only if a variable is equal to something?
Issue I’d like to add the –platform option only if the variable ‘platform’ is equal to ‘arm64’, otherwise the option should not be passed in. And I don’t want to duplicate the whole command and use an if-else. platform=$(uname -m)
Continue readingBatch File input validation – Make sure user entered an integer
Issue I’m experimenting with a Windows batch file to perform a simple operation which requires the user to enter a non-negative integer. I’m using simple batch-file techniques to get user input: @ECHO OFF SET /P UserInput=Please Enter a Number: The
Continue readingIL2CPP vs Mono scripting. How to find what breaks IL2CPP script?
Issue I am new to Unity development, so this is totally unexpected behavior for me that I have no idea how to deal with. My application runs perfectly on Android 10 device when complied using mono. However compilation with IL2CPP
Continue readingAre there any decent scripting languages that use functional programming?
Issue I’ve been reading a bit about functional programming recently and am keen to get have a bit of a play. are there any decent scripting languages that support functional programming? I find that the bulk of my ad-hoc programming
Continue readingQuote a path in a shell script
Issue I have a shell script that uses base64 to encode a value and store it in a variable. encoded="$(cat $pathtofile|base64 -w 0)" This worked until I ended up with a $pathtofile that had a special character in it. Now
Continue readingHow to Generate File of a determinate Size in Windows?
Issue How is the Best and fastest way to do it? Solution I found this Page, I try it and work great. To create a single File use fsutil file createnew filename filesize To create a lot of Files use
Continue readingPowershell 7+ Cannot Administer IIS 10 with the IISAdministration Module
Issue The following code will work (only sometimes though ??) with older versions of PowerShell but not at all with version 7+. All I want to do is create a new Application Pool in IIS 10+. The documentation is very
Continue readingHow to count the number of occurences of a word in several files?
Issue I have a directory containing a lot of files. I would like to display with one shell command the list of all the xml files in the directory with the number of times a specific word appears in each
Continue readingHow to concat variable and string in bash script
Issue How to concat variable and string in bash script ? val1 = Variable1 + “any string ” eg : val1 = $i + “-i-*” where i = 24thMarch I want echo val1 : 24thMarch-i-* What is proper proper to
Continue readingHow can I determine if a variable exists from within the Groovy code running in the Scripting Engine?
Issue How can I determine if a variable exists from within the Groovy code running in the Scripting Engine? The variable was put by ScriptEngine’s put method Solution In a groovy.lang.Script there is a method public Binding getBinding(). And groovy.lang.Binding
Continue readingModifying an Avaya CMS script (.acsauto) with Powershell and the resulting script won't run
Issue I have an avaya CMS script that is setup to extract team data so it can be imported into Power BI. The script is working fine, but I have to go in and manually edit the file in Notepad
Continue readingBatch files – number of command line arguments
Issue Just converting some shell scripts into batch files and there is one thing I can’t seem to find…and that is a simple count of the number of command line arguments. eg. if you have: myapp foo bar In Shell:
Continue readingPerl script that takes linux path as input from the user till a directory and need to get the output of all the directories with common name
Issue I have written Perl script that takes linux path as input from user until a certain directory and prints all the directories inside that which have the common name for example, if user input is /user/images/mobile_photos/ inside mobile_photos I
Continue readingDo you know tool building tree of include files in project\file?
Issue Say, I’d like to have a tool (or script?) taking project (or .h file) and building searchable tree of “includes” included into it (of included into of included into and so so on). Is there exist something like this?
Continue readingHow to get Powershell to run SH scripts
Issue Can someone please tell me how I get Powershell to run .sh scripts? It keeps just trying to open the file i need in Notepad when I run this command: .\update-version.sh 123 I’ve added .SH to my PATHEXT environment
Continue readingInvoke function whose name is stored in a variable in bash
Issue Let’s say I have: function x { echo “x” } call_func=”x” Now, I can simply use eval as follows: eval $call_func but I was wondering if there was some other way of invoking the function (if it exists) whose
Continue readingInvoke function whose name is stored in a variable in bash
Issue Let’s say I have: function x { echo “x” } call_func=”x” Now, I can simply use eval as follows: eval $call_func but I was wondering if there was some other way of invoking the function (if it exists) whose
Continue readingDelete all but the most recent X files in bash
Issue Is there a simple way, in a pretty standard UNIX environment with bash, to run a command to delete all but the most recent X files from a directory? To give a bit more of a concrete example, imagine
Continue readingDelete all but the most recent X files in bash
Issue Is there a simple way, in a pretty standard UNIX environment with bash, to run a command to delete all but the most recent X files from a directory? To give a bit more of a concrete example, imagine
Continue readingCan I retrieve a list of AD OUs using a variable?
Issue I am trying make a form to allow me to enter site name in a textbox and get all of the OUs for that specific site. I can get the powershell command to work if I enter the site
Continue readingWindows Forms SendKeys using Read-Host
Issue Apologies if this question has already been answered on another thread, but I went looking for my specific query and I couldn’t anything. The issue I have is sending keystrokes to a Read-Host command. When I do this, nothing
Continue readingshebang env preferred python version
Issue I have some python-2.x scripts which I copy between different systems, Debian and Arch linux. Debian install python as ‘/usr/bin/python’ while Arch installs it as ‘/usr/bin/python2’. A problem is that on Arch linux ‘/usr/bin/python’ also exists which refers to
Continue readingHow to simulate a pwm semnal python script
Issue I need to Simulate Saw-Tooth voltage (4.5 – 0.5V) a total of 30 times . And I don’t know how to do it only with python scripts without special library or something. I have this function, but how I
Continue readingHow to terminate 2 background processes running in bash script?
Issue I want these 2 background processes to end, for example, after pressing CTRL + C, the only thing I found that could help, but this does not work correctly: python3 script1.py & python3 script2.py & trap "trap – SIGTERM
Continue readingHow to terminate 2 background processes running in bash script?
Issue I want these 2 background processes to end, for example, after pressing CTRL + C, the only thing I found that could help, but this does not work correctly: python3 script1.py & python3 script2.py & trap "trap – SIGTERM
Continue readingHow to interpolate several values contained in a variable into a json string
Issue I have a parsed variable obtained after parsing some text: parsed=$(echo "PA-232 message1 GX-1234 message2 PER-10 message3" | grep -Eo ‘[A-Z]+-[0-9]+’) parsed contains a bunch of ids: echo $parsed PA-232 GX-1234 PER-10 The next thing I have to do
Continue readingHow to pass boolean values to a PowerShell script from a command prompt
Issue I have to invoke a PowerShell script from a batch file. One of the arguments to the script is a boolean value: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -File .\RunScript.ps1 -Turn 1 -Unify $false The command fails with the following error: Cannot process
Continue readingbash ldapsearch take input from file
Issue I have a simple ldapsearch bash script to return the user email when searched by ID. I made it take and argument as its input since at the time I only needed to run it once or twice. I’m
Continue readingDynamic case statement in bash
Issue I’m trying to figure out how to create a dynamic case statement in a bash script. For example, let’s say I have the output of an awk statement with the following contents red green blue In this scenario, the
Continue readingHow to know the directory where the current script lies
Issue When writing a script, I’d like to know where lies the current script, in order to locate other files. With a regular Scala script, I know how to do so, but with an Ammonite script I don’t. Solution Instead
Continue readingHow do I create my own custom command line script in zsh?
Issue I want to be able to run simple one line commands on my terminal, but instead of them being complicated I want them to be very simple, writing my own commands for these complex command lines that I have
Continue readingRandom number from a range in a Bash Script
Issue I need to generate a random port number between 2000-65000 from a shell script. The problem is $RANDOM is a 15-bit number, so I’m stuck! PORT=$(($RANDOM%63000+2001)) would work nicely if it wasn’t for the size limitation. Does anyone have
Continue readingCygwin save package selections for later reinstall
Issue I was wondering if there is a way to save the current package selections for cygwin for a later reinstall or porting on a different system. It would be really great to: run a command to export a list
Continue readingGame not detecting touched event
Issue I was trying to make a script for my NPC, that will place a bodyvelocity inside player that touched the glove that NPC Got in his hand, however it didn’t do anything. I tried to make a touch event
Continue readingHow to run a PowerShell script within a Windows batch file
Issue How do I have a PowerShell script embedded within the same file as a Windows batch script? I know this kind of thing is possible in other scenarios: Embedding SQL in a batch script using sqlcmd and a clever
Continue readingHow do I change owner and group owner of files and directories?
Issue I want to change the owner and the group owner for all the files in the current working directories with a single line command. I don’t want to have double line as follows; sudo chown you <some_file> chgrp new_group
Continue readingPowerShell display files size as KB, MB, or GB
Issue I have a section of a PowerShell script that gets the file size of a specified directory. I am able to get the values for different units of measurement into variables, but I don’t know a good way to
Continue readingPowerShell analog to "dir /a:d" (Win) or "ls -d */" (Bash)
Issue I simply want to list all of the directories under my current working directory, using PowerShell. This is easy from a Bash shell: ls -d */ or cmd.exe in Windows: dir /a:d Using PowerShell however I cannot seem to
Continue readingDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" How does that work?
Issue I need to get the path of the script. I can do that using pwd if I am already in the same directory, I searched online and I found this DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Continue readingDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" How does that work?
Issue I need to get the path of the script. I can do that using pwd if I am already in the same directory, I searched online and I found this DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Continue readingHow do I reload ZSH config files without replacing the current shell?
Issue How do I tell ZSH to reload itself, as if it’s a freshly invoked shell, but without losing the history? The context for this is that I’ve spent a long time building my ZSH setup, and I’d hate to
Continue readingExtract version number from file in shell script
Issue I’m trying to write a bash script that increments the version number which is given in {major}.{minor}.{revision} For example. 1.2.13 Is there a good way to easily extract those 3 numbers using something like sed or awk such that
Continue readingWhy won't this array property populate
Issue I have two multidimensional arrays that have some shared data. The elements are not in the same order between the two arrays, nor do the property names match in every instance. However, the fields to compare will always have
Continue readingFind substring in shell script variable
Issue I have a string $VAR=”I-UAT”; in my shell script code. I need a conditional statement to check if “UAT” is present in that string. What command should I use to get either true or false boolean as output? Or
Continue readingHow to implement tasks in powershell based on a script parameter (i.e. msbuild, gradle)
Issue Is it possible to implement a task-style system in PowerShell so that you could do the following: .\script.ps1 build # runs build() function .\script.ps1 publish # runs publish() function I was hoping to use PowerShell for building/publishing an application
Continue readingReplace special characters using Windows batch script
Issue I am trying to replace these special characters using Windows batch scripting. Existing To My "name" is XXXX My \"name\" is XXXX My name is XXX\X My name is XXX\\X I tried to achieve this through Informatica Cloud. It
Continue readingLUA script that will return false until an elapsed time (of random value between two fixed limits) has passed – and then it returns true?
Issue I trying to write a small/simple LUA script that returns false unless enough time has elapsed, when it should return true. The period of time should be randomly chosen between two constant fixed upper and lower limits (preferably in
Continue reading.cmd vs .ps1 in Path
Issue I have added a folder to my Path that contains a foo.cmd batch file and foo.ps1 powershell script. (The batch file is there to run the powershell script with a bypassed execution policy.) When in powershell/command prompt I run
Continue readingLinux write basic commands and make it executable using single line of code
Issue Hello is this possible to create a file with these line of codes below and make it as an executable file on single line of code? Currently I’m doing manually. Your response is highly appreciated. Thank you Manual Steps
Continue readingPython script to highlight differences (not additions) in two CSV files
Issue I have a basic script that compares two CSV files and records the changes in a new one (daily-diff.csv): CSV (import 1): Address Price 101 Main Street £50,000 102 Main Street £100,000 CSV (import 2): Address Price 101 Main
Continue readingOptimising Python script for scraping to avoid getting blocked/ draining resources
Issue I have a fairly basic Python script that scrapes a property website, and stores the address and price in a csv file. There are over 5000 listings to go through but I find my current code times out after
Continue readingHow do I make Perl scripts recognize command-line parameters in the Win32 cmd console?
Issue When I invoke my Perl scripts in the Windows environment without invoking perl first, the parameters are not passed to my script. For example, C:\> C:\my-perl-scripts\foo.pl bar invokes foo.pl but doesn’t recognize bar as a parameter (@ARGV is empty).
Continue readingRemove the last line from a file in Bash
Issue I have a file, foo.txt, containing the following lines: a b c I want a simple command that results in the contents of foo.txt being: a b Solution Using GNU sed: sed -i ‘$ d’ foo.txt The -i option
Continue readingDetermine if a function exists in bash
Issue Currently I’m doing some unit tests which are executed from bash. Unit tests are initialized, executed and cleaned up in a bash script. This script usualy contains an init(), execute() and cleanup() functions. But they are not mandatory. I’d
Continue readingHow to urlencode data for curl command?
Issue I am trying to write a bash script for testing that takes a parameter and sends it through curl to web site. I need to url encode the value to make sure that special characters are processed properly. What
Continue readingsubprocess popen is returning blanck output
Issue On trying to run the grep for the output of previous command using popen returning blank without any error proc1cmd = "grep " + fetchname1 p1 = subprocess.Popen([‘kubectl’, ‘get’, ‘abr’, ‘-A’], stdout=subprocess.PIPE) p2 = subprocess.Popen(proc1cmd, shell=True, stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Continue readingPSQL database creation from script
Issue I have an issue with automatic database creation. I have created create_database.sql file with following code: BEGIN; \i schema.sql \i domains.sql \i sequences.sql \i tables.sql \i dane/insert_users.sql \i dane/insert_default_expenses.sql \i dane/insert_default_incomes.sql \i dane/insert_default_payments.sql \i dane/insert_user_incomes.sql \i dane/insert_user_expenses.sql \i dane/insert_user_payments.sql
Continue readingtotal size of group of files selected with 'find'
Issue For instance, I have a large filesystem that is filling up faster than I expected. So I look for what’s being added: find /rapidly_shrinking_drive/ -type f -mtime -1 -ls | less And I find, well, lots of stuff. Thousands
Continue readingHow can I read a list of filenames from a file in bash?
Issue I’m trying to write a bash script that will process a list of files whose names are stored one per line in an input file, something the likes of find . -type f -mtime +15 > /tmp/filelist.txt for F
Continue readingHandling & symbol in filename
Issue There is a "&" symbol in one of the files’ name. If I try to use mv command, I’m not able to correctly get the file name. Actual filename : abc&def.xls mv command: mv $home/abc&def.xls $enter/abc&def.xls But I’m getting
Continue readingUsing 'pipenv run' can I run a script outside of the project folder?
Issue In my project folder, which I initiated pipenv shell. When in that folder and not in the pipenv virtual enviroment. I can use the command pipenv run script.py and it works. However, when I change directory and move outside
Continue readingPython text based game – How to show the correct output when player wins or loses game by reaching the room with the villain
Issue My code works fine moving between rooms and collecting items but when player gets to the Food court where the villain is without all 6 items in the inventory it should output the player lost, or if player has
Continue readingHow to convert piped/awk output to string/variable
Issue I’m trying to create a bash function that automatically updates a cli tool. So far I’ve managed to get this: update_cli_tool () { # the following will automatically be redirected to …/releases/tag/vX.X.X # there I get the location from
Continue readingIn a Bash script, how can I exit the entire script if a certain condition occurs?
Issue I’m writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I’ll just abort the tests. Is there a way
Continue readingCreating an array from a text file in Bash
Issue A script takes a URL, parses it for the required fields, and redirects its output to be saved in a file, file.txt. The output is saved on a new line each time a field has been found. file.txt A
Continue readingPowershell – Get Worksheets from several excel files and save them into one excel file -with original file name as worksheet name-
Issue I have searched the following code in the net, that works, but keep the original name of the worksheets when adding them in new excel file. I would need to set the original file name as the worksheet names.
Continue reading