Combining text files with Execute command

Post Reply
Shawn_Anderson
Newbie
Posts: 8
Joined: Mon Apr 17, 2017 3:45 pm

Combining text files with Execute command

Post 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.
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Combining text files with Execute command

Post 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.
Shawn_Anderson
Newbie
Posts: 8
Joined: Mon Apr 17, 2017 3:45 pm

Re: Combining text files with Execute command

Post 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
User avatar
neecerp
Member
Posts: 27
Joined: Tue Jun 05, 2012 9:21 pm

Re: Combining text files with Execute command

Post by neecerp »

Any chance you still have this flow and any support scripts that go with it?
I need some help with how to do something like this.
Post Reply