Utilizing awk
The awk command helps you to do the identical factor with its toupper and tolower choices. The command within the script proven within the earlier instance could possibly be finished this fashion as an alternative:
echo $dept | awk '{print toupper($0)}' >> depts
The reverse (switching to lowercase) would appear like this:
echo $dept | awk '{print tolower($0)}' >> depts
Utilizing sed
The sed (stream editor) command additionally does a terrific job of switching between upper- and lowercase. This command would have the identical impact as the primary of the 2 proven above.
echo $dept | sed 's/[a-z]/U&/g' >> depts
Switching from uppercase to lowercase would merely contain changing the U close to the top of the road with an L.
echo $dept | sed 's/[A-Z]/L&/g' >> depts
Manipulating textual content in a file
Each awk and sed additionally let you change the case of textual content for whole recordsdata. So, you simply discovered your boss wished these division names in all lowercase? No downside. Simply run a command like this with the file title offered:
$ awk '{print tolower($0)}' depts finance billing bookkeeping
If you wish to overwrite the depts file, as an alternative of simply displaying its contents in lowercase, you would wish to do one thing like this: