Skip to content

Instantly share code, notes, and snippets.

@NiharG15
Created October 9, 2015 07:16
Show Gist options
  • Save NiharG15/f5d1a4a7b278ba0f0fa5 to your computer and use it in GitHub Desktop.
Save NiharG15/f5d1a4a7b278ba0f0fa5 to your computer and use it in GitHub Desktop.
A shell script to capitalize first and last characters of every word in given file
#!/bin/bash
#This script capitalizes the first and last letters of each word in infile and writes the output to outfile
#This regex matches first character of every word which is converted to uppercase by \u\1
sed -e 's/\b\(.\)/\u\1/g' infile > tmpfile
#This regex matches last character of every word which is converted to uppercase by \u\1
sed -e 's/\(.\)\b/\u\1/g' tmpfile > outfile
#Delete temporary file
rm tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment