Easily change files on your Linux system with a simple command.

This command will change the default port for the SSH server on your Linux machine. jason@jason-desktop:~$ perl -pi -e ‘s/^#?Port 22$/Port 443/’ /etc/ssh/sshd_configjason@jason-desktop:~$ perl -pi -e ‘s/^#?Port 22$/Port 443/’ /etc/ssh/sshd_config Then run this command to restart the SSH server. jason@jason-desktop:~$ sudo service ssh restartjason@jason-desktop:~$ sudo service ssh restart This will work very well. This is … Read more

Convert text from comma delimited to newline delimited with a simple command.

Some text files are shipped as comma-delimited files. This can be annoying to fix, but it can be done with the Linux command line. Here is an example of comma-delimited text. jason@jason-desktop:~/Documents$ cat banlist.txt | head -c 200 ; echo 10.34.28.4, 103.11.70.143, 103.11.70.143, 103.22.245.6, 107.20.178.108, 108.163.248.74, 108.21.102.146, 108.62.110.25, 108.62.33.114, 108.62.33.114, 108.62.62.164, 109.162.20.227, 109.162.20.28, 109.1jason@jason-desktop:~/Documents$ cat … Read more

Trim multiple spaces with sed into a normal string.

To trim multiple spaces from a sentence and turn it back into properly readable text, use this sed syntax. sed ‘s/ \+/ /g’sed ‘s/ \+/ /g’ This is an example. echo "Hello, this sentence has multiple spaces in it and needs fixing." Hello, this sentence has multiple spaces in it and needs fixing.echo "Hello, this … Read more

Fun with sed on Linux.

The sed command can be used to reverse text. This is a very interesting feature. Provide a text string, and it will be reversed. jason@jason-Virtual-Machine:~$ sed ‘/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/./Hello. /’ <<< ‘This is a long sentence in reverse. This is a lot of fun.’ Hello. .nuf fo tol a si sihT .esrever ni ecnetnes gnol a si … Read more

Search and replace text in a file with ed.

I have a text file containing this string. deusexmachina:Documents jason$ cat out Darwin deusexmachina.local 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64deusexmachina:Documents jason$ cat out Darwin deusexmachina.local 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64 And I want to replace one instance of the word … Read more

Use sed to filter text, this is very useful.

This sed sample will filter out all HTML opening and closing tags in HTML sed -e ‘s/<[^>]*>//g’ blog.txtsed -e ‘s/<[^>]*>//g’ blog.txt This is an example of the usage of this one-liner. 4.4 Sun Nov 11 jason@Yog-Sothoth 0: $ sed -e ‘s/<[^>]*>//g’ index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   Securitron GNU/Linux pages.   … Read more

Another way to get the actual IP address of your machine.

This is yet another way to get the actual IP address of your Linux machine on a LAN. This returns just the IP address of your Linux computer. jason@jason-Lenovo-H50-55:~$ ip a | awk ‘/inet / { print $2 }’ | sed -n 2p 192.168.1.4/24jason@jason-Lenovo-H50-55:~$ ip a | awk ‘/inet / { print $2 }’ | … Read more

Very cool Linux text processing tricks.

Align all text right on an 80 column width. jason@jason-Lenovo-H50-55:~/Documents$ ls -hula | sed -e :a -e ‘s/^.\{1,80\}$/ &/;ta’ total 872K drwxr-xr-x 2 jason jason 4.0K May 4 08:48 . drwxr-xr-x 23 jason jason 4.0K May 3 20:51 .. -rw-r–r– 1 jason jason 848K Apr 21 13:01 altis_insurgency_altis.pbo -rwxrwxr-x 1 jason jason 166 Apr 22 … Read more

Some awesome tricks with awk, grep and sed.

Reading a large text file and then finding all words that contain between 5 and 7 vowels. Notice I am not using cat. jason@Yog-Sothoth:~/Documents$ egrep ‘^([^aieou]*[aieou]){5,7}[^aieou]*$’ < pg768.txt | wc -l 284jason@Yog-Sothoth:~/Documents$ egrep ‘^([^aieou]*[aieou]){5,7}[^aieou]*$’ < pg768.txt | wc -l 284 Count the number of times a single word appears in a text file. jason@Yog-Sothoth:~/Documents$ egrep … Read more

How to use the sed command to filter text files in Linux and other useful shell tricks for the Linux command line.

Using sed to filter a text file and change a specific character for another. In this case the ” character becomes the ‘ character using the magic of the sed command. Since I am using a character the shell also uses I have to escape it out so the command will work. This can make … Read more

How to strip all of the text out of a text file and leave only the numbers and formatting. And other sed tricks.

How to strip all numbers out of a text stream This is how to remove all text from the output of a file and only keep the other formatting. homer@deep-thought ~/Desktop/b $ fortune -l | sed s/[a-z]/\ /gi; : 3:15 . . – .   , ! — ’84homer@deep-thought ~/Desktop/b $ fortune -l | sed … Read more

Useful shell tips. How to search and replace characters or words with the bash shell.

Search and replace on the bash shell is very useful for various one-liner shell commands. The below example shows how to replace a # character with a * character. jason@DESKTOP-R72SPS3:/mnt/c/Users/johnc/Documents$ cat ip.c | sed ‘s/#/*/gi;’ *include <stdio.h>   int main() { printf(".");   return 0; }jason@DESKTOP-R72SPS3:/mnt/c/Users/johnc/Documents$ cat ip.c | sed ‘s/#/*/gi;’ *include <stdio.h> int main() … Read more

Basic text filtering with sed. Very useful when you are manipulating text files.

This example uses sed to replace the beginning word of a sentence. Administrator@WIN-EM8GK0ROU41 ~ $ echo "this is a line of text." | sed "s/this/This/gi;" This is a line of text.Administrator@WIN-EM8GK0ROU41 ~ $ echo "this is a line of text." | sed "s/this/This/gi;" This is a line of text. This is a better way to … Read more

How to search and replace text in a file with sed. Not using cat.

The sed command is very useful for searching and replacing text in a file. This is how to search for and replace a text string in a file. Homer@bejiitas ~ $ sed -i ‘s/&lt;main&gt;/&lt;mein&gt;/gi;’ my.cHomer@bejiitas ~ $ sed -i ‘s/&lt;main&gt;/&lt;mein&gt;/gi;’ my.c This is how to search and replace text in a file and leave a … Read more

How to filter text with the sed command. This is useful for various shell tricks.

Using wildcards on the Linux command line This is a standard listing of files with wildcards in the bash shell. homer@deep-thought ~/Documents $ ls *.wad basenew.wad cc4-tex.wad city-heat.wad dark.wad doom.wad plutonia.wad scythe2.wad SKYTEST.wad brick.wad cchest4.wad consoleCopy.wad doom2.wad hexen.wad RIII.wad scythex.wad SODfinal.wadhomer@deep-thought ~/Documents $ ls *.wad basenew.wad cc4-tex.wad city-heat.wad dark.wad doom.wad plutonia.wad scythe2.wad SKYTEST.wad brick.wad cchest4.wad … Read more

Converting a comma delimited file to newline delimited. Using sed to perform the conversion.

The search and replace dialog in Gedit. I have used this to convert a comma-delimited file to a newline delimited file. I had saved a huge long list of IP addresses that I had to put into the ban list on my forums, and the list was comma-delimited, but the latest PHPBB software will not … Read more