Perl oneliner to extract host and port from URL [closed] - perl

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am aiming to extract host and port number from the url. Could you please update me any examples to do it using perl regex or sed/awk etc?
echo "https://xxxx:port/services"
I am looking for an oneliner to extract host and port.

perl -MURI -nle'$u = URI->new($_); printf "%s:%s\n", $u->host, $u->port'
Works even if the port is implied. (e.g. http://stackoverflow.com/)
Works for HTTP, HTTPS, FTP and some others that have the concept of a host and port.
Specifying file to process to Perl one-liner

I do this so often that I made a little sprintf-like utility for it: App::url. This isn't useful if you can't install the module and easily use the command-line program, but locally it's quite helpful to extract and rearrange things:
$ url "%h:%p" http://www.example.com/a/b/c
www.example.com:80
$ url "%h:%p" http://www.example.com/a/b/c https://www2.example.org:444
www.example.com:80
www2.example.org:444
$ url "%h -> %I" http://www.example.com/a/b/c
www.example.com -> 93.184.216.34
Often I use this with a little AppleScript I wrote to get all the URLs from all the tabs in Safari:
$ safari-tabs 2>&1 | xargs url %h
www.google.com
github.com
dnschecker.org
securitytrails.com
st.aticpan.org

Related

How to find port on windows (using pid or processes name) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 29 days ago.
Improve this question
How to find port on windows (using pid or processes name)
I know the PID, but I need the port on which the processes are running
you can use the following CMD command (Open it as administrator)
netstat -aon | findstr PID
There more different ways to find process port available here.
The accepted answer to the question that Nikita's answer links to - https://stackoverflow.com/a/48199/45375 - can be adapted to your needs with the following PowerShell command (assumes that the PID of interest is stored in $yourPid):
(Get-NetTCPConnection | Where-Object OwningProcess -eq $yourPid).LocalPort |
Select-Object -Unique
Note that even weeding out duplicates can result in multiple ports getting returned.
See also:
Get-NetTCPConnection

how to print only "cmd" from ps command using perl [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I need to extract the cmd from the output of ps. I know that I can use the following to write only the PID using the ps command:
ps ax | perl -nle 'print $1 if /^ *([0-9]+)/'
I am wondering if I could write only the command using something similar.
You can use
ps axhw -o cmd
h disables headers.
w prevents the output from being truncated.
-o cmd identifies which fields to output.
See also the c output modifier.

gvim 8.2 doesn't redraw the screen when editing a git commit message in windows 10 powershell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I installed vim on windows 10 using chocolatey. When I edit a file in powershell, everything works great! I even got copy and paste to work. However, when I edit a git commit message, vim doesn't redraw my screen properly. If I force a screen redraw, I can see my updated text properly, but that is super annoying.
I configured git to use vim with:
git config --global core.editor vim
How can I make vim behave properly?
TLDR
Giving git the direct fully-qualified path to my vim executable fixed things, and I don't know why:
git config --global core.editor "'C:\tools\vim\vim82\vim.exe' -f -i NONE"
Single quotes around the path are important because git doesn't know how to handle paths with backslashes.
Double quotes around the whole configuration are important so that git doesn't apply -f -f NONE to the git config command.
I found -f -i NONE on this answer, and I don't know what it does, but git commit didn't work without it.
How I found the full path
vim adds a c:\windows\vim.bat file, which is what powershell uses to launch vim when you type vim:
PS C:\Users\heath> Get-Command vim
CommandType Name Version Source
----------- ---- ------- ------
Application vim.bat 0.0.0.0 C:\windows\vim.bat
vim.bat is pretty simple:
#echo off
rem -- Run Vim --
rem # uninstall key: vim82 #
setlocal
set VIM_EXE_DIR=C:\tools\vim\vim82
if exist "%VIM%\vim82\vim.exe" set VIM_EXE_DIR=%VIM%\vim82
if exist "%VIMRUNTIME%\vim.exe" set VIM_EXE_DIR=%VIMRUNTIME%
if not exist "%VIM_EXE_DIR%\vim.exe" (
echo "%VIM_EXE_DIR%\vim.exe" not found
goto :eof
)
"%VIM_EXE_DIR%\vim.exe" %*
Thus, my full vim path is C:\tools\vim\vim82\vim.exe

How command prompt works in all operating system [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How command prompt communicate with hardware
if i give mkdir command it will create the directory
how this command works internally
can i create own commands.
You need to notice the difference between the OS and the shell. Shell is only a user-land program. When you type a command, the command is the name of another program(or some built-in command in shell itself), shell find the corresponding program and execute it.
The operations at this level is much higher than hardware, it's just user-land program call.
For mkdir, you type which mkdir then will find the path of this program named mkdir. If you want to create your own, just compile your own program and run it from shell.
First of all MKDIR doesn't change the Directory it Makes the new directory.
& These program internally runs like a Bash Script/Batch File, which are few predefined codes in the OS.
You can create your own command by creating Batch File, For which you need Notepad, Little Programing Skill & Output Parameters you Want To Achieve.
This Link Might help Creating CMD File

FTP client command line put directory [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Is there a command line FTP client where you can upload a whole directory?
Or does anyone know how to make a bat file that uses window's ftp client to upload a directory?
Any thing would be helpful, thanks.
Try with WinSCP (see CLI docs) or NcFTP
Here's how you can do it in a batch file:
#ftp -i -s:"%~f0"&GOTO:EOF
open ftp.host.com
username
password
folder
mput "*.*"
disconnect
bye
replace the "parameters"(ftp.host.com, username, password, folder) with your own and save it as a .bat
Here's more information on ftp scripts in batch