×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

grep question

grep question

grep question

(OP)
I am trying to use the grep command to search for lines that contain a particular string at a certain character position.  Is there any way to tell grep to only search for the string at a specified position of each line?

Example-

00001JIM SMITH     35LL
00002MIKE JONES    30LL
00003STEVE SIMMS   02LL

Let's say I only want to return lines that contain '02' at the 20th character position.

Thanks in advance...

RE: grep question

hpux

RE is a regular expression
RERE is a regular expression made from two reg exps
. is any character except newline
RE /{m/} is exactly m repetitions of RE

so

grep -e ^./{20/}20 filename

gets you start of line, 20 characters and a 20 in the line.

good luck, you might have to modify the code slightly for your O/S.

Lynn

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources