UNIX::SED::How to replace numericacharacter (lower case to upper case) in the .txt file ?

Posted on 2007-10-11
Last Modified: 2012-06-27

I have a records like this in the file.txt:
20071010                Add     0       625306  1800076         USD     5y      1825    2555    32733.29
20071010                Add     0       625306  1800076         USD     3M      1825    2555    32733.29
20071010                Add     0       625306  1800076         USD     10y      1825    2555    32733.29

In the 7th field, I have a data 5y, 3M, 10y

I would like to change the all small letter to upper case (eg: 5y to 5Y and 10y to 10Y)

Can you tell me how can we do this in SED ?

I have tried with below command, but it's not showing correctly.  Please advise.

sed 's/[0-9]*y/[0-9]*Y/g' file.txt
Question by:cmurugavel
    LVL 84

    Expert Comment

    sed s/y/Y/
    LVL 48

    Accepted Solution

    sed "s/\([0-9]\)y/\1Y/g" file.txt
    LVL 84

    Assisted Solution

    to only change y folllowing a digit
    sed 's/\([0-9]\)y/\1Y/g'
    LVL 1

    Author Comment

    I like to share the mark to ozo and tintin. Let me know how to do it
    LVL 9

    Expert Comment

    you can use sed to do that, however be careful of other letters in other columns..awk is a better tool to use. Unless you have restrictions on the tools to use, you can try this:

    awk '{$7=tolower($7);print}' "file" > newfile

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
    Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now