Tag Archives: sed

Script to count number of logged in users to OpenVPN

To get that information you need to query your openvpn-status.log file, which usually resides in /var/log/openvpn/openvpn-status.log. A normal cat will show the following: OpenVPN CLIENT LIST Updated,Wed Mar 5 11:57:51 2019 Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since someuser,someip:55530,100686479,319036434,Tue Mar 5 … Continue reading

Posted in Linux | Tagged , , | Leave a comment

A tiny script to replace all occurrences of a string in a file with another string

sed -i ‘s/original/new/g’ filename.txt This basically replaces every occurrence of the “original” string with the “new” string in the file named “filename.txt” e.g. sed -i ‘s/192.168.0.1/192.168.1.1/g’ /etc/fstab Will replace all occurrences of the IP “192.168.0.1” with the IP “192.168.1.1” in … Continue reading

Posted in Linux | Tagged , , , | 1 Comment

Replacing a string with another in a text file using sed

sed -i ‘s/old-test/new-text/g’ filename This replaces the word old-test with the word new-text in the file named filename.

Posted in Uncategorized | Tagged , , , | Leave a comment

How to extract a number from a string (not a file) in Bash

export hobba=ksjdjf123ksks export nokka=`sed “s/[^0-9]//g” <<< $hobba` echo $nokka 123 Sources: http://stackoverflow.com/questions/13055889/sed-with-a-literal-string-not-input-file, http://stackoverflow.com/questions/6388046/extract-integer-from-string-using-bash

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Delete the last line in a text file using sed

sed -i ‘$d’ hobba -i: to change the file itself, not copy contents to another file or something$d: delete the last linehobba: the file name

| Tagged , | Leave a comment