![]() ![]() ![]() I really like this idea and some of the comments here are very helpful, thanks a ton! But first things first: 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)\")" 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)\")"īut jsed need now to be more “generic”, accepting several kind of templates. 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)\")" In fact the problem was because $ need to be escaped with \ when using in command line.įor (count, line) in enumerate(readlines(stdin)) So we can process differently headers than data / skip headers using count so template will be for (count, line) in enumerate(readlines(stdin)) PS: maybe we should have something like for (count, line) in enumerate(readlines(stdin)) Or using multiline cat data.txt | jsed """Ī “specialised” Julia template could be set using a parameter passed jsed but in most case it shouldn’t be necessary. Or more complex process on stream of lines.Ĭommands could be given like cat data.txt | jsed "line = uppercase(line)" "cur_name, cur_symb, _, value = split(line)" "cur_symb = strip(cur_symb, )" "println(\"$(lpad(cur_name, 10)) $(lpad(value, 3)) $(cur_symb)\")" We should also probably make a command line tool for that purpose which could be used to write oneliners likeĬat data.txt | jsed "println(uppercase(line))" Maybe we should write a kind of tutorial about data cleaning with Julia (taking inspiration from the large number of tutorials about data cleaning teaching how to use iconv, head, tail, tr, wc, split, sort, uniq, cut, paste, join, grep, sed, awk, … and show that we can do all these tasks with ONE tool: Julia (I know it’s not the Unix philosophy) Print(f"")Ĭur_name, cur_symb, _, value = split(line) My answer is supposed to be a more portable (stub of a) solution.I wanted for example to do something similar to this Python script.Ĭur_name, cur_symb, _, value = line.split() I think dategrep from this other answer is probably the right tool. Timestamps in question contain no characters that would break the sed code or be special in regex, so in this case it should be safe. In sed the expanded variables will be interpreted at least as regular expressions, but in general as code. Printf will simply print what $start and $end expand to. Usually timestamps in a log are sorted, but in your example they are not. This can be avoided if timestamps in the file are already sorted use sort -m if they are. ![]() If logfile is large, sort will have to do lot of work. Other lines with this exact timestamp won't be printed. It may be the $end line we injected, or it may be a line from logfile with this exact timestamp. The output will include exactly one line with the $end timestamp. The output will include the $start line we injected and all lines from logfile with this exact timestamp (not necessarily in this order). We can inject them then we need to sort by timestamps and then your sed should work.įortunately the timestamps in your logfile are in a format that can easily be sorted with LC_ALL=C sort -k 1,1, if only all the timestamps end with +02:00. Sed operates on strings, it does not understand the concept of dates. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |