bash shell script - Find word in text file

Posted on 2006-03-27
Last Modified: 2010-04-21
I have a text file that I want to hunt for an item then echo it.

The data in the file looks like this:

ITEM:  1411    DATE:  3/1/03

What I want to do is pull the number right after ITEM: and the date after DATE:, there are several spaces between ITEM: and the number as well as several spaces after DATE:

I want to put the following in a variable, so I can echo it later:

Any ideas?

Thanks in advance!
Question by:cybrthug
    1 Comment
    LVL 84

    Accepted Solution

    variable=`awk '/ITEM: .* DATE: /{print $2 ";" $4}' file`

    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

    When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    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…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now