- IT 리더가 지목한 AI 가치 실현의 최대 걸림돌은 ‘비용 관리’
- Los CIO consideran que la gestión de costes puede acabar con el valor de la IA
- 칼럼 | AI 에이전트, 지금까지의 어떤 기술과도 다르다
- The $23 Echo Dot deal is a great deal to upgrade your smart home this Black Friday
- Amazon's Echo Spot smart alarm clock is almost half off this Black Friday
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: