Save Radare2 terminal output into text file for Mac - bash

I am trying to use Radare2 to save opcode sequences from PE32 files. Does anyone know how I can save the output Radare2 prints onto terminal after I call the "pd" command onto a text file? I am also wondering if there might be a way to do this in python as well using the r2pipe library.

Related

How to print .txt file containing esc/pos commands using command prompt in windows?

I am trying to print ESC/pos commands from the .txt file using windows command prompt.
Let me explain what I tried so far:
I have connected my Epson Tm-m30 printer. Using a virtual port driver I can print the .txt file using the following command:
print /d:COM1 'file path'
Now my question: as it is, ESC/pos printer needs to print the ESC/pos commands like a paper cut, barcode printing, etc. When I paste the ESC/pos commands in the .txt file, it is print as it is, not as ESC/pos commands.
I am trying to print The following ESC/pos commands:
\x1B\x40
\x1D(k\x0d\x00\x30\x50\x30TEST PRINT
\x1D(k\x03\x00\x30\x51\x
But while printing it is printing it looks like above, not as ESC commands.
How do I print ESC/pos commands using a .txt file?
There are no commands built into Windows by default, so the following options are possible.
Use the tools distributed by EPSON
Send Data Tool
Issuing Receipts with Barcodes
Use a free tool published by someone somewhere
Create your own with a script tool such as PowerShell
about_Special_Characters
Make your own with C++/C#/VB etc.
Regex.Unescape(String) Method
Regular Expression Language - Quick Reference
Create a file with binary data instead of text and copy it to COM1 with the copy /b command

Saving file in TextEdit from command line on MacOS

I have a batch (8k) of damaged .odt files. I discovered that opening and saving them in TextEdit fixed them. I would like to script that using node.js, but cannot find a way to save and close file from terminal. Is there a command to do that?
The final goal is to convert them to pdf, for which I am already using a script that runs LibreOffice in headless mode.

Redirect text file changes to batch file output

I am using a build tool which only writes its output to a text file, and I would like to use that build tool on a build server. The tool is Atmel Studio, and I try to start a build this way.
While the build is running, it writes its result to a text file, then the process of the tool ends.
I would like to have the text file output written to stdout, i.e. I would like the same effect as if the tool would write to the commandline output instead of the text file, in order to see what is going on during the build.
Is there any kind of command on a batch file to achieve this? If not, is there a good alternative?

using google-apps-script to try to create a bash shell script from spreadsheet

We are trying to generate a bash shell script for use on a Linux system from values stored in a Google spreadsheet and we are having difficulties.
I can create the script contents fine and save the resultant file to Google drive but the problems come about when I try to use the file on a Linux box. When the file is downloaded as plain text the encoding is set to UTF-8 which Linux thinks is a binary file when I try to execute it. The other problem we are having is the line endings are forcibly set to the host PC which is a windows box so I get CRLF not LF as required by the Linux machine. I was wondering if there was anyway in Google app scripting to forcibly give me ASCII encoding and UNIX line ending somehow. I'd rather not have to pipe the file contents through strings and dos2unix before being able to use it.

How do I copy and paste from bash to vim and vice-versa using only the keyboard?

Using this command:
http://www.hypexr.org/bash_tutorial.php#vi
I'm able to use vim commands in the bash. But, what I'd like to do is copy and paste from that (bash) into vim and vice-versa.
I know there are other posts on here using the middle mouse button, but I use putty to connect to linux boxes, and the middle mouse performs a selection, just like the left click drag.
I'm not looking for something that will modify my windows clipboard. Selecting in vim is useful for transfering stuff to and from windows, but I'd like a solution that will work both through putty and using a direct terminal.
Thanks in advance...
I use the copy&paste feature in screen. ctrl-[ to enter copy mode and ctrl-] to paste. There are different buffers and the ability to dump to a file. It's pretty powerful. The default is to copy lines, but you can curtail by columns join display lines into a single copied line (and other options). And since you would likely already be in screen when you run vim, you would have the paste buffer available. I also have hooks to copy the buffer to/from the X clipboard.
I don't know if that can help you, but I have installed a utility called xclip, which shares the X11 clipboard with VIM. I mainly use it to copy and paste between instances of VIM running in different terminal windows.
I typically use xclip with the following mappings, which keep a very similar behaviour to the usual yank and paste commands, but using the clipboard:
nmap `yy :.w !xclip<CR><CR>
vmap `y :w !xclip<CR><CR>
nmap `p :.r!xclip -o<CR>
nmap `P :.-r!xclip -o<CR>
Use the * (or + in X Windows) registers to reference the system clipboard. Anything yanked-to or pasted-from those registers can be used to cooperate with other applications:
Cut/Copy examples
"*yy : copy current line to the system clipbard
gg"*yG : copy current file to the system clipbard
"*dd : cut current line to the system clipbard
etc, etc
Paste examples
"*p : paste the system clipbard
Or in insert mode:
i Ctrl+r *
Or
i Ctrl+r Ctrl+p *
(the last one pastes withouth formatting, useful to avoid those ugly pastes from the OS clipboard where each indented line appears more and more shifted)
You can copy from/to the clipboard in both vim and bash using ctrl + ins for copy, and shift + ins for paste.

Resources