twoodcc Posted October 27, 2008 Share Posted October 27, 2008 ok, so what i want to do is make some sort of script, either applescript or shell script, that will do the following: take out from a command in the terminal put that output into a text file already on my computer. the only thing is that i need to put the output in the file kinda weird: i need to take it and put each character of output on a new line, but not create new lines example: take output of command 'uptime' (up 32 days, 23:09) place in file 'myFile' output: ... key u key p key space key 3 key 2 key space key d ... anyone have any idea on how to do this? thanks in advance Link to comment Share on other sites More sharing options...
Airr Posted November 13, 2008 Share Posted November 13, 2008 Quick and dirty way with bash: #!/bin/bash upTime=`uptime` upTimeLength=${#upTime} upTimeIndex=0 while [ $upTimeIndex -le $upTimeLength ]; do echo ${upTime:$upTimeIndex:1} >> tmpfile.txt let upTimeIndex=upTimeIndex+1 done AIR. Link to comment Share on other sites More sharing options...
Airr Posted November 13, 2008 Share Posted November 13, 2008 And a quick and dirty AppleScript. Save this as an app in Script Editor and execute from the Finder: set myText to "" set theFile to "tmpfile2.txt" as file specification set upTime to do shell script ("uptime") set upTimeLength to the number of characters of upTime set upTimeIndex to 1 repeat while upTimeIndex is less than or equal to upTimeLength set myText to myText & (character upTimeIndex of upTime) & return set upTimeIndex to upTimeIndex + 1 end repeat open for access theFile with write permission write myText to theFile starting at eof as text close access theFile AIR. Link to comment Share on other sites More sharing options...
acr4 Posted November 17, 2008 Share Posted November 17, 2008 uptime | perl -ne 'split //;foreach(@_){print "$_\n";};' >> myFile echo -e `uptime | sed 's/\(.\)/\1\\\n/g'` >> myFile Link to comment Share on other sites More sharing options...
Recommended Posts