A little exercise using a sequence of bash shell commands (I'm including the "$" shell prompt, to make it clear which lines are actual commands; the lines without "$" are either keyboard input or command output):
$ cat <<EOF > test.in
one o n e
two t w o
three t h r e e
EOF
$ perl -pe 's/(\w+)/\U$1/' < test.in > test.out
$ cat test.out
ONE o n e
TWO t w o
THREE t h r e e
If you want to store the one-line perl script as an executable file (so that you don't have to type perl -pe 's/(\w+)/\U$1/' every time you want to up-case the first word of every line in a data stream), you would do this:
$ cat <<EOF > upcase-firstword
#!/usr/bin/perl -p
s/(\w+)/\U$1/;
EOF
$ chmod +x upcase-firstword
$ upcase-firstword < test.in > test2.out
$ diff test.out test2.out
Move the "upcase-firstword" file to some directory in your PATH, and you can run it no matter which directory you are in at the moment. (You can give it a shorter name if you like.)
Using the "cat" command to write a perl script like that can be lots of fun, although many programmers would not consider it to be their preferred method for programming. |