- Herencia, propósito y creatividad confluyen sobre un manto tecnológico en los irrepetibles UMusic Hotels
- OpenAI, SoftBank, Oracle lead $500B Project Stargate to ramp up AI infra in the US
- 오픈AI, 700조원 규모 'AI 데이터센터' 프로젝트 착수··· 소프트뱅크·오라클 참여
- From Election Day to Inauguration: How Cybersecurity Safeguards Democracy | McAfee Blog
- The end of digital transformation, the rise of AI transformation
Converting between uppercase and lowercase on the Linux command line
Using awk
The awk command lets you do the same thing with its toupper and tolower options. The command in the script shown in the previous example could be done this way instead:
echo $dept | awk '{print toupper($0)}' >> depts
The reverse (switching to lowercase) would look like this:
echo $dept | awk '{print tolower($0)}' >> depts
Using sed
The sed (stream editor) command also does a great job of switching between upper- and lowercase. This command would have the same effect as the first of the two shown above.
echo $dept | sed 's/[a-z]/U&/g' >> depts
Switching from uppercase to lowercase would simply involve replacing the U near the end of the line with an L.
echo $dept | sed 's/[A-Z]/L&/g' >> depts
Manipulating text in a file
Both awk and sed also allow you to change the case of text for entire files. So, you just found out your boss wanted those department names in all lowercase? No problem. Just run a command like this with the file name provided:
$ awk '{print tolower($0)}' depts finance billing bookkeeping
If you want to overwrite the depts file, instead of just displaying its contents in lowercase, you would need to do something like this: