In fact the problem was because $
need to be escaped with \
when using in command line.
WIP:
jsed.jl
code = join(ARGS, ";")
template = """
for (count, line) in enumerate(readlines(stdin))
$(code)
end
"""
eval(Meta.parse(template))
Usage:
cat data.txt | julia jsed.jl """
line = uppercase(line)
cur_name, cur_symb, _, value = split(line)
cur_symb = strip(cur_symb, ['(', ')'])
println(\"\$(count) \$(lpad(cur_name, 10)) \$(lpad(value, 3)) \$(cur_symb)\")
"""
or as one-liner
cat data.txt | julia jsed.jl "line = uppercase(line)" "cur_name, cur_symb, _, value = split(line)" "cur_symb = strip(cur_symb, ['(', ')'])" "println(\"\$(count) \$(lpad(cur_name, 10)) \$(lpad(value, 3)) \$(cur_symb)\")"
or
cat data.txt | julia jsed.jl "line = uppercase(line); cur_name, cur_symb, _, value = split(line); cur_symb = strip(cur_symb, ['(', ')']); println(\"\$(count) \$(lpad(cur_name, 10)) \$(lpad(value, 3)) \$(cur_symb)\")"
but jsed
need now to be more “generic”, accepting several kind of templates.
We also need to have jsed
as a system command (ie available in path) so we could do:
cat data.txt | jsed "line = uppercase(line)" "cur_name, cur_symb, _, value = split(line)" "cur_symb = strip(cur_symb, ['(', ')'])" "println(\"\$(count) \$(lpad(cur_name, 10)) \$(lpad(value, 3)) \$(cur_symb)\")"