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

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

Released Wednesday, 8th May 2024
Good episode? Give it some love!
HPR4113: Today I Learnt, sed hold/pattern space use.

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

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

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

Wednesday, 8th May 2024
Good episode? Give it some love!
Rate Episode

Today I Learnt, sedhold/pattern space use.

Sgoti talksabout using sed hold/pattern spaces.

  • Tags: TIL, sed

Ifixed 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}awkcat=${bindir}catchmod=${bindir}chmoddate=${bindir}dateecho=${bindir}echofind=${bindir}findls=${bindir}lsmktemp=${bindir}mktempsed=${bindir}seduniq=${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).* ]; thentmpdir1=$(ls -d /tmp/$(${date} +%F).*)${echo} -e "The directory already exists.\n${tmpdir1}"elsetmpdir0=$(${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.txttmpdoc1=${tmpdir1}/$(${date} +%Y%m%d)bash.vimtmpdoc2=${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 'hs/[^0-9a-zA-Z]//gGs/\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>4k0Aiabbr ali; alias NAME=''<ESC>B

iabbr ; ()<Left><Left>

EOL1

# bash.vim body.${ls} -1 ${bindir}| ${sed} -n ' {hs/[^0-9a-zA-Z]//gGs/\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 ' {hs/[^0-9a-zA-Z]//gGs/\n/ /s/(.*) (.*)/\<CR>1=${bindir}2/p}' >> ${tmpdoc1}

${sed} -i '/{[}/d; /${bindir}[/d' ${tmpdoc1}

${echo} -e "\nStep 3: $(${date} +%F), $(${date} +%T)";

# Sed script here-document.${cat} > ${tmpdoc2} << "EOL2"#!/usr/bin/sed -f

EOL2

# Sed script body.${ls} -1 ${bindir}| ${sed} -n 'hs/[^0-9a-zA-Z]//gGs/\n/ /s/(.*) (.*)/s/\<2\>/${1}/g/p' >> ${tmpdoc2}${sed} -i '/[/d' ${tmpdoc2}

${find} "${tmpdir1}" -type d -exec chmod -R =700 {} +;${find} "${tmpdir1}" -type f -exec chmod -R =600 {} +;

${echo} -e "\nStep 4: $(${date} +%F), $(${date} +%T)";

exit;

This work is licensed under a Creative CommonsAttribution-ShareAlike 4.0 International License.

Show More
Rate

Join Podchaser to...

  • Rate podcasts and episodes
  • Follow podcasts and creators
  • Create podcast and episode lists
  • & much more

Episode Tags

Do you host or manage this podcast?
Claim and edit this page to your liking.
,

Unlock more with Podchaser Pro

  • Audience Insights
  • Contact Information
  • Demographics
  • Charts
  • Sponsor History
  • and More!
Pro Features