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 > 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
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.)$ 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
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.
In reply to Re^3: Changing the first word to uppercase
by graff
in thread Changing the first word to uppercase
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |