|Oct 12, 2008, 09:49 PM||#1|
Append text to file with shell script
I have a script that gathers data and will add it to a text file, without overwriting the current text.
I can't quite get it to work properly.
I've tried printing directly, but all this does is overwrite the existing text.
echo $output >> disk_space.txt
I've also tried using VI to edit the file, but I can't get that working either.
vi $file <<EOF :$ $ o $output ESC :w :x EOF
|Oct 13, 2008, 12:20 AM||#2|
Your script should indeed append to disk_space.txt, not overwrite it, and I've never see it fail to work as specified. Perhaps there's another problem. For example, perhaps disk_space.txt already exists and does not have write permission so you can't modify it. Or perhaps you are running this command while the script is cd'ed to another location, so it's writing to /somewhere_else/disk_space.txt. You might change it to an absolute path.
What kind of value is in $output? If it might contain punctuation characters, you'd be safer to put double quotes around it. In fact, I'd recommend doing that in any case.
With my suggestions:
echo "$output" >> /Users/myname/Desktop/disk_space.txt
Since programs like vi respond to one keypress at a time, rather than read a line at a time like most Unix shell commands, I don't think you can script a vi interaction the way you are trying to.
Oh do pay attention 007. In the wrong hands, this cylindrical 12-core Mac Pro with three 4K displays, FirePro graphics, and Thunderbolt 2 could be very dangerous.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Append Text to Text File in Applescript||BobRon||Mac Programming||2||Mar 23, 2014 02:52 PM|
|Shell script in Automator for Bit Rate of Audio File||drmjdoyle||Mac Basics and Help||0||Mar 5, 2014 05:18 PM|
|How to? Short cut to append text to doc\note (using alfred or other)||kevindosi||Mac Applications and Mac App Store||1||Jan 20, 2014 02:58 PM|
|Apple script batch shell script||prramesh||Mac Programming||5||Sep 15, 2013 03:35 AM|
|Anyway to write a script that write text into an existing text file||hypmatize||Mac Programming||10||Jun 12, 2013 05:52 AM|
All times are GMT -5. The time now is 12:32 AM.