Executing Terminal Commands

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Executing Terminal Commands

Mark Romano
I have an OS X terminal command that takes a large text file and splits it into rows of 1800 or less (with headers). I’d like to execute commands like this from Lasso but not sure how to structure the sys_process code necessary to make this happen. Not having any luck after reading the LassoGuide on sys_process.

Any help from the list would be greatly appreciated.

Lasso 9.2.3
OSX 10.11.6
Server 5.2


Example:
——————————————————————————————————

#!/bin/bash

cd desktop/TargetFolder

FILE=$(ls -1 | grep ITEMS.txt)
NAME=${FILE%%.txt}

head -4 $FILE > header.txt
tail -n +5 $FILE > data.txt

split -l 1800 data.txt

for a in x??
    do
        cat header.txt $a > $NAME.$a.txt
    done

mv $FILE $NAME.orig.txt
rm header.txt data.txt x??

——————————————————————————————————



Thank you,

Mark Romano




#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Executing Terminal Commands

Ke Carlton-3
Hello,

Your paths should all be absolute. For example cd desktop is likely to fail
due to where the script starts.

The basic syntax is:

local(p) = sys_process('/absolute/path/to/script.sh')

#p->wait

'errors: ' #p->readerror + '\n\n'
'result: ' #p->readstring + '\n\n'

#p->close

And you can also invoke bash directly like this:

local(p) = sys_process(
'/bin/bash', (:
'-c',
' echo "Hello" '
)
)

It's important to check both readerror and readstring because different
commands can use either or.

Ke



On Tue, Jun 6, 2017 at 7:20 AM Mark Romano <[hidden email]> wrote:

> I have an OS X terminal command that takes a large text file and splits it
> into rows of 1800 or less (with headers). I’d like to execute commands like
> this from Lasso but not sure how to structure the sys_process code
> necessary to make this happen. Not having any luck after reading the
> LassoGuide on sys_process.
>
> Any help from the list would be greatly appreciated.
>
> Lasso 9.2.3
> OSX 10.11.6
> Server 5.2
>
>
> Example:
> ——————————————————————————————————
>
> #!/bin/bash
>
> cd desktop/TargetFolder
>
> FILE=$(ls -1 | grep ITEMS.txt)
> NAME=${FILE%%.txt}
>
> head -4 $FILE > header.txt
> tail -n +5 $FILE > data.txt
>
> split -l 1800 data.txt
>
> for a in x??
>     do
>         cat header.txt $a > $NAME.$a.txt
>     done
>
> mv $FILE $NAME.orig.txt
> rm header.txt data.txt x??
>
> ——————————————————————————————————
>
>
>
> Thank you,
>
> Mark Romano
>
>
>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Executing Terminal Commands

Mark Romano
Thank you, Ke!





Mark Romano




> On Jun 6, 2017, at 3:21 PM, Ke Carlton <[hidden email]> wrote:
>
> Hello,
>
> Your paths should all be absolute. For example cd desktop is likely to fail
> due to where the script starts.
>
> The basic syntax is:
>
> local(p) = sys_process('/absolute/path/to/script.sh')
>
> #p->wait
>
> 'errors: ' #p->readerror + '\n\n'
> 'result: ' #p->readstring + '\n\n'
>
> #p->close
>
> And you can also invoke bash directly like this:
>
> local(p) = sys_process(
> '/bin/bash', (:
> '-c',
> ' echo "Hello" '
> )
> )
>
> It's important to check both readerror and readstring because different
> commands can use either or.
>
> Ke
>
>
>
> On Tue, Jun 6, 2017 at 7:20 AM Mark Romano <[hidden email]> wrote:
>
>> I have an OS X terminal command that takes a large text file and splits it
>> into rows of 1800 or less (with headers). I’d like to execute commands like
>> this from Lasso but not sure how to structure the sys_process code
>> necessary to make this happen. Not having any luck after reading the
>> LassoGuide on sys_process.
>>
>> Any help from the list would be greatly appreciated.
>>
>> Lasso 9.2.3
>> OSX 10.11.6
>> Server 5.2
>>
>>
>> Example:
>> ——————————————————————————————————
>>
>> #!/bin/bash
>>
>> cd desktop/TargetFolder
>>
>> FILE=$(ls -1 | grep ITEMS.txt)
>> NAME=${FILE%%.txt}
>>
>> head -4 $FILE > header.txt
>> tail -n +5 $FILE > data.txt
>>
>> split -l 1800 data.txt
>>
>> for a in x??
>>    do
>>        cat header.txt $a > $NAME.$a.txt
>>    done
>>
>> mv $FILE $NAME.orig.txt
>> rm header.txt data.txt x??
>>
>> ——————————————————————————————————
>>
>>
>>
>> Thank you,
>>
>> Mark Romano
>>
>>
>>
>>
>> #############################################################
>>
>> This message is sent to you because you are subscribed to
>>  the mailing list Lasso [hidden email]
>> Official list archives available at http://www.lassotalk.com
>> To unsubscribe, E-mail to: <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>