Page 1 of 1

Combining text files with Execute command

Posted: Tue Aug 08, 2017 9:50 pm
by Shawn_Anderson
We're receiving several .csv files from a client that need to be combined into one by adding the contents of the second file after the contents of the first. I've been trying to use cat in the Execute Command element but am having trouble getting it to work in Switch. In the Mac terminal "cat file2.csv >> file1.csv" gives me what we need, but switch is producing no output when I drag file2.csv and file1.csv into the flow.

Tried a bunch of variations, but the execute command is currently set up like this

Command or path
/path/to/script/cat.sh
Arguments
"%1" "%2"
Output
File at path
Copy Input: No
Output extension: Auto
Disregard exit code

Bash Script
cat.sh
#!/bin/bash
cat "${1}" >> "${2}"

Permissions are 755 on the cat.sh bash script. Also tried running it direct with the cat command in place instead of the path to the separate script file.

Any ideas. I've gotten sed and awk commands to work in similar scripts through trial and error in the past. I'm wondering if it's not presenting file1.csv correctly as the output at %2. Getting everything in the right place in Execute is a pain.

Re: Combining text files with Execute command

Posted: Wed Aug 09, 2017 12:48 pm
by Padawan
Are there errors logged by the command when you execute it in Switch?

You can see regular output (stdout), error output (stderr), exit codes and the actual command being executed in the Switch messages when debug logging is enabled. In my experience this helps a lot when trying to find out why Execute Command is not behaving as expected.

Running the command direct won't work since you are using redirection, you will have to use a shell script in between like you do now.

Re: Combining text files with Execute command

Posted: Tue Aug 15, 2017 4:54 pm
by Shawn_Anderson
Thank you Padawan

That was exactly what I needed. I didn't realize debug logging would show issues with Execute. stderr showed issues with how it was applying the path in %2. Changed it to point to a different file and location and it's working great now.

Shawn