Hands-On Data Science with the Command Line by Jason Morris

Hands-On Data Science with the Command Line by Jason Morris

Author:Jason Morris
Language: eng
Format: epub
Tags: COM018000 - COMPUTERS / Data Processing, COM089000 - COMPUTERS / Data Visualization, COM062000 - COMPUTERS / Data Modeling and Design
Publisher: Packt Publishing
Published: 2019-01-31T21:44:32+00:00


Text injection of text files

We're going to create a function that can inject text into an existing file. Here's our function:

lineinfile() {

FILE=$1 ; shift

LINE=”^$1$” ; shift

CONTEXT=”$1.*” ; shift

MODE=${1:-add} ; shift

case “${MODE}” in

add)

grep -s “${LINE}” “${FILE}” || sed -i -e “s/\(${CONTEXT}\)/\1\n${LINE}/” “${FILE}”

;;

del)

grep -s “${LINE}” “${FILE}” || sed -i -e “/${LINE}/d” “${FILE}”

;;

esac

}

The intended usage is as follows:

lineinfile <filename> <string> <insert-after-context-string> <add | [del]>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.