jump x lines after match

replace next line after line match

sed '/^3/{ n; s/.*/x/ }' <(seq 7)

replace second line after line match

sed '/^3/{ n; n; s/.*/x/ }' <(seq 7)

append/insert a new line after match

sed '/^3/a new_line' <(seq 7)

jump 1 line after match and append a new line

sed '/^3/!{ p; d }; n; a new_line' <(seq 7)

jump 2 lines after match and insert a new line

sed '/^3/!{ p; d }; n; n; a new_line' <(seq 7)

add menu on tint2 taskbar

1 – add the repository that contains jgmenu package for debian 9 stretch

cat >> /etc/apt/sources.list <<EOF
deb http://pkg.bunsenlabs.org/debian stretch-backports main
EOF

2 – install the key of added repository

curl -L https://ddl.bunsenlabs.org/ddl/BunsenLabs-RELEASE.asc | apt-key add -

3 – install jgmenu

apt update && apt install jgmenu

4 – create a .desktop file. * change Icon value

cat > ~/.local/share/applications/jgmenu.desktop <<EOF
[Desktop Entry]
Name=jgmenu
Exec=jgmenu_run &> /dev/null
Type=Application
Icon=/path/to/svg/icon/file.svg
Categories=System
EOF

5 – add launcher entry to jgmenu on tint2rc file

cat >> ~/.config/tint2/tint2rc <<EOF
# Launcher
launcher_icon_size = 22
startup_notifications = 0
launcher_item_app = jgmenu.desktop
EOF

meansure wifi signal strength/power

using /proc file

awk 'END { print int($3*10/7)"%" }' /proc/net/wireless

using iw command

specifying wifi interface

iw wlp2s0 station dump | awk '$1 ~ "signal:" { print int(int($2+100)*1.9) >= 100 ? "100%" : int(int($2+100)*1.9)"%" }'

getting wifi interface automatically

iw $( ip route | awk '/^default.*dev/ { for (x=1; x<NF; x++) if ( $x ~ "dev" ) print $(x+1) }' ) station dump | awk '$1 ~ "signal:" { print int(int($2+100)*1.9) >= 100 ? "100%" : int(int($2+100)*1.9)"%" }'

create/append file using heredoc

use here document to create a file using cat

create a file maintaining interpolation

cat > file1 <<EOF
$HOME
abc
$(hostname)
EOF

suppress interpolation creating a file

cat > file2 <<'EOF'
$HOME
abc
$(hostname)
EOF

append content to a file

cat >> file2 <<FIN
new content
FIN

if the file was created with success execute a command printing a message

cat <<FIN> file3 && echo file created
def
FIN

execute command after append content to a file

cat <<EOF>> file3; wc -l file3
ghi
EOF

create a formatted file inside an if statement(use of TAB is mandatory)

if true; then
        cat > file4 <<-EOF
srv07:
  host: 192.168.0.7
  user: root
        EOF
fi

* if you copy this block of code, delete heredoc lines begin and use TAB

control remotely keyboard and mouse over ssh

1 – install x2x package on the remote machine

apt install x2x

2 – connect from source machine to remote machine and control X display

ssh -X user@192.168.0.7 x2x -north -to :0

* move mouse cursor to up/down borders of screen to alternate between machines

connect on remote machine and change keyboard layout

1 – configure ssh on the client machine to reuse an already established connection

cat >> ~/.ssh/config <<EOF
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r
EOF

2 – connect on the remote machine and execute a command on X11 session to change keyboard layout

sshpass -p "passwdHere" ssh -o StrictHostKeyChecking=no -X user@192.168.0.7 x2x -north -north -to :0 &
sleep 1
ssh -o StrictHostKeyChecking=no -X user@192.168.0.7 DISPLAY=:0 'setxkbmap pt'
reset
echo 'connection ready!'