Hacker Public Radio

HPR4113: Today I Learnt, sed hold/pattern space use.


Listen Later

Today I Learnt, sed
hold/pattern space use.
Sgoti talks
about using sed hold/pattern spaces.
Tags: TIL, sed
I
fixed the ${ls} /usr/bin to ${ls} ${bindir}
issue mentioned in the show.
#!/bin/bash
# License: GPL v3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#Name: grab-bin.sh
#Purpose: Link your binaries.
#Version: beta 0.07
#Author: SGOTI (Some Guy On The Internet)
#Date: 2023-12-17
#variables:
bindir=/usr/bin/
awk=${bindir}awk
cat=${bindir}cat
chmod=${bindir}chmod
date=${bindir}date
echo=${bindir}echo
find=${bindir}find
ls=${bindir}ls
mktemp=${bindir}mktemp
sed=${bindir}sed
uniq=${bindir}uniq
#start:
${echo} -e "nStep 0: $(${date} +%F), $(${date} +%T)";
# Create the /tmp/ directory to place the files.
function mkt (){
if [ -d /tmp/$(${date} +%F).* ]; then
tmpdir1=$(ls -d /tmp/$(${date} +%F).*)
${echo} -e "The directory already exists.n${tmpdir1}"
else
tmpdir0=$(${mktemp} -d /tmp/$(${date} +%F).XXXXXXXX)
tmpdir1=${tmpdir0}
${find} "${tmpdir1}" -type d -exec ${chmod} -R =700 {} +;
${echo} "Had to create ${tmpdir1}"
fi
}
mkt
${echo} -e "nStep 1: $(${date} +%F), $(${date} +%T)";
# Files created by this script.
tmpdoc0=${tmpdir1}/$(${date} +%Y%m%d)variables.txt
tmpdoc1=${tmpdir1}/$(${date} +%Y%m%d)bash.vim
tmpdoc2=${tmpdir1}/$(${date} +%Y%m%d)sed-script.sed
# Here-document to build the first document (variables.txt).
${cat} > ${tmpdoc0} << "EOL0"
bindir=/usr/bin/
EOL0
# variables.txt body.
${ls} -1 ${bindir}
| ${sed} -n '
h
s/[^0-9a-zA-Z]//g
G
s/n/ /
s/(.*) (.*)/1=${bindir}2/p
' >> ${tmpdoc0}
${sed} -i '/[/d' ${tmpdoc0}
${echo} -e "nStep 2: $(${date} +%F), $(${date} +%T)";
# Bash.vim here-document.
${cat} > ${tmpdoc1} << "EOL1"
iabbr case;
case ${var_name} in
<CR> [yY])
<CR> ${echo} 'User said, "Yes"';
<CR> ;;
<CR>
<CR> [nN])
<CR> ${echo} 'User said, "No"';
<CR> ;;
<CR>
<CR> [qQ])
<CR> ${echo} "Let's get outta here.";
<CR> exit
<CR> ;;
<CR>
<CR> *)
<CR> ${echo} "Good Heavens! Someone broke the script I'm writing.";
<CR> exit
<CR> ;;
<CR>esac
iabbr here; ${cat} << _EOD_<CR>_EOD_<CR><ESC>2k0
iabbr func function NAME () {<CR><CR>}<UP>
iabbr if; if []; then<CR><ESC>Ielse<CR>${echo} "Good Heavens!"<CR><ESC>Ifi<ESC>4k0A
iabbr ali; alias NAME=''<ESC>B
iabbr ; ()<Left><Left>
EOL1
# bash.vim body.
${ls} -1 ${bindir}
| ${sed} -n ' {
h
s/[^0-9a-zA-Z]//g
G
s/n/ /
s/(.*) (.*)/iabbr 1 ${2}/p
}
' >> ${tmpdoc1}
# Bash.vim here-document second pass.
${cat} >> ${tmpdoc1} << EOL1-5
iabbr vars;
bindir=/usr/bin/
<CR>
EOL1-5
# bash.vim body second pass.
${ls} -1 ${bindir}
| ${sed} -n ' {
h
s/[^0-9a-zA-Z]//g
G
s/n/ /
s/(.*) (.*)/<CR>1=${bindir}2/p
}
' >> ${
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
Security Now (Audio) by TWiT

Security Now (Audio)

1,970 Listeners

Off The Hook by 2600 Enterprises

Off The Hook

117 Listeners

No Agenda Show by Adam Curry & John C. Dvorak

No Agenda Show

5,942 Listeners

The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

283 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

265 Listeners

BSD Now by JT Pennington

BSD Now

89 Listeners

Open Source Security by Josh Bressers

Open Source Security

43 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

154 Listeners

The Linux Cast by The Linux Cast

The Linux Cast

35 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

7,876 Listeners

This Week in Linux by TuxDigital Network

This Week in Linux

36 Listeners

Linux Dev Time by The Late Night Linux Family

Linux Dev Time

21 Listeners

Hacking Humans by N2K Networks

Hacking Humans

314 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

92 Listeners

Linux Matters by Linux Matters

Linux Matters

20 Listeners