does anyone know a way to get a piece of a text file and load it into a line of an ansi flie? [5:17 PM] reddit / bbs ---------------------------------------------------------------------- robertc19850209 · 2023-07-12 21:24 ​ i want everything in the quotes of this highlighted line to be sent to the second or third line (only the first 80 characters if there are 81 or more of course) of an ansi file. preferably with custom color encoding if possible https://preview.redd.it/dwuq384rplbb1.png?width=3360&format=png&auto=w ebp&s=888d7076fe84c8fc88962eeedd50b13b95f0e9ae ---------------------------------------------------------------------- robertc19850209 · 2023-07-12 21:25 i should mention i am asking how to do this on debain linux ---------------------------------------------------------------------- robertc19850209 · 2023-07-12 21:30 furthermore a watch command incorporated so it will run again every minute or so so that the info is up to date ---------------------------------------------------------------------- digitlman · 2023-07-13 00:07 Use copy/paste? Or do you mean, dynamically (e.g. merge 2 files on demand)? ---------------------------------------------------------------------- robertc19850209 · 2023-07-13 00:12 take what's in that part of the text file, and add it to a line of an ansi art file. i'm not sure how to explain it right now ---------------------------------------------------------------------- digitlman · 2023-07-13 00:28 "ansi art file" is not a script that you can execute. It sounds like maybe you want a program or script that merges 2 streams (a portion of some output of a process?) into a single ANSI-encoded display file. Many BBS programs have special codes you can embed in display files to do this kind of thing, but you didn't mention if this is for a BBS or what BBS software or really any details at all. ---------------------------------------------------------------------- robertc19850209 · 2023-07-13 00:36 it is for a bbs, enigma specifically on linux and need to grab some metadata from an audio stream for a radio station and show to the users what song is now playing within the bbs interface. i'm sorry i didn't get very specific earlier. ---------------------------------------------------------------------- robertc19850209 · 2023-07-13 00:37 that's the ends, i need a bash script that are the means or a one line command as my means ---------------------------------------------------------------------- robertc19850209 · 2023-07-13 00:52 desired result, just slip the text from the json file to line 2 of this ansi art file ​ https://preview.redd.it/d60w01w2rmbb1.png?width=3360&format=png&auto=w ebp&s=c2566838749904f8067ee1994433d1b50fee83b7 ---------------------------------------------------------------------- toadstoolpp · 2023-07-13 13:15 save the part you want and use thedraw block load ---------------------------------------------------------------------- onefiveonesix · 2023-07-13 18:20 You could use Python and the built-in JSON module of its standard library to parse the contents and then do processing. You could also get really quick & dirty and use grep in the shell. You do have more than one line in the JSON file with the string “title” so grep’ing will return more than one line but let’s assume you only have one “title” row in the JSON file. The command would be something like: ```grep title *json_filename* > title.txt``` That will return all rows from the JSON file that contain the word “title” and redirects the output to a file called title.txt instead of displaying in the shell. You’d then want to split the row returned at the colon symbol to isolate the actual title. Once you have it isolated, it can be inserted/appended to the “ANSI” file through arbitrary shell commands. You’d also want to setup a cronjob in your crontab to fire the script(s) that will handle on this on a schedule. If the JSON is hosted remotely on a different server, you may need to use something like curl to pull the data down locally. Bear in mind there’s so many ways to accomplish this and this is just what I’m thinking of at first pass. ---------------------------------------------------------------------- robertc19850209 · 2023-07-13 19:51 ok this sounds doable, is there anything i can do to only get the first title, i will need the second one later for another bbs, but this is all i need now. ---------------------------------------------------------------------- onefiveonesix · 2023-07-13 20:28 Yes, you can use the -m arg with a grep command to specify how many hits to return (e.g., -m1). So the full command would be: ```grep -m1 “title” your_json_file.json > title.txt``` And of course there is a wealth of info on the ways you can use grep in its built-in manual (```man grep```). Edit: If you wanted to have the row from the JSON file stored in a shell variable instead of being written to a file, you could put this in the script: song_title=\`grep -m1 “title” your_json_file.json\` ---------------------------------------------------------------------- robertc19850209 · 2023-07-13 23:39 thanks, a friend helped me setup a python script, all that's left to do is get it into that \*.ans file somehow ---------------------------------------------------------------------- onefiveonesix · 2023-07-14 00:26 I would use the sed utility to do a full-line replacement in your .ans file. The syntax is ```sed -i ‘2s/.*/song_title_goes_here’ ansi_filename.ans``` This does an in-place edit (i.e., it overwrites the file directly) and tells sed to replace the 2nd line of the specified file with the string provided. The 2 before the s is where you tell it what line you want replaced. You could execute this via Python using the subprocess module’s call function or in a shell script. For where I put song_title_goes_here, that’s where you’d concatenate in the variable that the song title is held in.