• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 583
  • Last Modified:

bash shell script - Find word in text file

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!
1 Solution
variable=`awk '/ITEM: .* DATE: /{print $2 ";" $4}' file`
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now