As usual, in Linux, there are more than 1 way to accomplish a task.
To convert a file (input.txt) to all lower case (output.txt), choose any ONE of the following:
- dd
$ dd if=input.txt of=output.txt conv=lcase
- tr
$ tr '[:upper:]' '[:lower:]' < input.txt > output.txt
- awk
$ awk '{ print tolower($0) }' input.txt > output.txt
- perl
$ perl -pe '$_= lc($_)' input.txt > output.txt
- sed
$ sed -e 's/\(.*\)/\L\1/' input.txt > output.txt
We use the backreference \1 to refer to the entire line and the \L to convert to lower case.
To convert a file (input.txt) to all upper case (output.txt):
- dd
$ dd if=input.txt of=output.txt conv=ucase
- tr
$ tr '[:lower:]' '[:upper:]' < input.txt > output.txt
- awk
$ awk '{ print toupper($0) }' input.txt > output.txt
- perl
$ perl -pe '$_= uc($_)' input.txt > output.txt
- sed
$ sed -e 's/\(.*\)/\U\1/' input.txt > output.txt
12 comments:
nice :-) . may come in handy. thanx.
thanks, always great to learn about sed ;)
The dd one surprised me, but that's linux ! Always surprising !
when converting accented vowels
some conversions fail but this one work
sed -e's/.*/\L&/'
Thanks for the useful article on tr command. More examples at
tr command example in unix
There's always something more to learn about sed. Thanks!
Awesome!!!!
tr function is great...:)
can we use cat command to convert text???
You can alway use text-converter.com
good article
it could be more easy with
#tr "a-z" "A-Z" < input.file
There are some examples over here as well: http://www.digitalinternals.com/script/shell-script-convert-uppercase-lowercase/414/
BASH SCRIPT WITH EMBEDDED PERL SCRIPT
#!/bin/bash
perl -i.bak -e '
while(<>) {
print "\L$_";
}
' $*
#!/bin/bash
perl -i.bak -e '
while(<>) {
print "\L$_";
}
' $*
Post a Comment