How to do it...

As with the exercise using Bash only, we are going to perform a similar recipe as follows:

Create a script called some-strs.sh with the following content and open a new terminal:

#!/bin/bashSTR="1234567890asdfghjkl"echo -n "First character "; sed 's/.//2g' <<< $STR # where N = 2 (N +1)echo -n "First three characters "; sed 's/.//4g' <<< $STRecho -n "Third character onwards "; sed -r 's/.{3}//' <<< $STRecho -n "Forth to sixth character "; sed -r 's/.{3}//;s/.//4g' <<< $STRecho -n "Last character by itself "; sed 's/.*\(.$\)/\1/' <<< $STRecho -n "Remove last character only "; sed 's/.$//' <<< $STR

Execute the script and review the results.

Create another script called more-strsng.sh and then execute it:

#!/bin/shGB_CSV="testdata/garbage.csv" ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.