JavaScript is normally for web based crap, you are looking a down to earth language. Since you're already using language that shall not be named, want to manipulate data, I think Python is the obvious choice. Here is something that demonstrates some terrible 5 minute hack you could do in python, I commented it so grandma can read it, though you probably won't need it.
Code
#!/usr/bin/env python3
"""
File.txt:
-----------------------------------------------------------------------------------------------
Ayy
Lmao -> ['Ayy\n', 'Lmao\n', 'Whatever']
Whatever
v
-to- heh()
v
Ayy
Lmao <- ['Ayy\n', 'Lmao\n', 'Lel']
Lel
-----------------------------------------------------------------------------------------------
"""
def heh(ayy):
""" do stuff to your data ;)"""
for off, dat in enumerate(ayy): # 0, line, 1, line, 2, line, etc.
if "Whatever" in ayy[off]: # find relevant line based on condition
ayy[off] = "Lel" # modify position in list with new data
return ayy
with open('file.txt', 'r') as file: # context manager for I/O - 'r' supports read/
data = list(file) # put each line into list - can also use file.read() and file.readline()
print(data)
wow = heh(data) # apply function `heh()` to reference `data` -> heh(data)
print('--After Change(s)--')
print(wow)
yah, yahornah = 'y', input('All good, y/n?')
if yahornah == yah:
with open('file.txt', 'w') as lel: # 'w' for write
for each in wow:
lel.write(each) # write out each in list to file
https://docs.python.org/3/tutorial/inputoutput.htmlhttps://docs.python.org/3.0/library/fileinput.html Should have used the second one
This post was edited by killg0re on Oct 29 2014 08:14am