How can I extract group-3-vm1 after I do this grep? Here’s the result: Answer This awk command replaces the grep and tail commands while also extracting the text of interest: How it works -F'[:/]’ This sets the field separator to either a colon or a slash. /Tracking URL/{n=$4;} This looks for line…
Tag: bash
How do i split output of “who -m”command in linux?
I want to split output of who command and store output in variable EX. I want to split this output like Answer The following should work: Giving:
In Unix, how to display welcome message if user has logged in from a particular IP (or host)?
I want to display one message if user XYZ has logged in from any IP (or host). Answer Check to see if you have environment variables such as SSH_CLIENT and SSH_CONNECTION set. If so, you can access these from scripts (perl, bash, etc…) to dynamically generate a welcome message. Below, is a simple perl s…
Embedding bash commands
I’m using virtualenvwrapper and trying to create a virtualenv using a version of python that’s not the default. What I’d like to do is: …But without the copy-paste. Is there a way to do this in one line? Answer is the correct way to write this as a one-liner. type is a POSIX standard u…
linux terminal text manipulation
I am now studying linux command line and this question is in my head for almost a week but i think still i have not found optimal solution, question is next: i have file with is formatted in a bad way one word on each line: as you see those are linux distros with version and release dates right formatting
Bash – How to print multi line strings (with ‘n’) using printf
i’m trying to print a multi line strings in printf this way I can’t do the following Is there any other way? Answer Quoting the variable should do the trick. In your example, however, you are getting double newlines.
Grep regexp for matching ip addresses in a file
I’m trying to search a file “Sessions” that contains IP addresses (among other useless junk). My Grep is failing to match, even though REGEXR is matching perfectly all the IPs perfectly … so I know the REGEX is correct … but when I GREP for this same pattern, not is returned. I&#…
Bash – Delete lines ending with a number
I need to remove only lines (in text file) ending with a number. Before: After: Answer Since you’re referencing my favorite movie, I’ll answer: Which translates to: Delete any line where there is either a space or a tab, followed by at least one digit, then any amount of spaces or tabs at the end …
Grabbing data between two commas
I am in the process of writing a simple script to grab battery information from acpi so I can format and output it. Currently, I am using cut to grab this information, but as the battery state changes, cut does not grab the correct data and instead will grab a portion of a string instead of the battery percen…
Adding server hostname to each line of ‘find’ output
I am in need of a listing of all files with a specific extension on a server. I need it to show the server hostname, file size, and absolute path of the file. or Almost get me there: joes_server 5473 /home/joe/pics/sunset.jpg 8522 /home/joe/pics/mountains.jpg I cannot figure out how to include the hostname on…