LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-25-2004, 08:18 PM   #1
provkitir
Member
 
Registered: Jul 2004
Location: Mass
Distribution: Freebsd 5.3, Debian sid 2.6.7
Posts: 101

Rep: Reputation: 15
quick grep question


Hi
i have a quick grep question, say there's a big file where there are many instances of "1125" on differnent lines. however, I just want the four letters before 1125, what's the grep command line to show only one of the many instances with only the "YYYY1125" as output?
I read thru man grep and most of which was regarding to the number of lines
thanks
 
Old 11-25-2004, 09:02 PM   #2
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
Code:
grep -oh [[:space:]]....1125[[:space:]] <datafile>
Or something along those lines may do the trick, depending on how your data file is laid out.

Cheers,

mj

Last edited by mjrich; 11-25-2004 at 09:05 PM.
 
Old 11-25-2004, 09:08 PM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
that would require a grep command piped through an awk command. have grep print the line, and have awk chop it down to what you want.
 
Old 11-25-2004, 09:29 PM   #4
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
The above grep command will work, as long as you happen to have a tab or some other delimiter before the four characters and the 1125, and only one 1125 per line. But that's a big if, I guess !

You could also use head/tail to chop the output, but awk would be more reliable, as per whansard's suggestion.
 
Old 11-25-2004, 09:32 PM   #5
provkitir
Member
 
Registered: Jul 2004
Location: Mass
Distribution: Freebsd 5.3, Debian sid 2.6.7
Posts: 101

Original Poster
Rep: Reputation: 15
cool!

it's working now! thanks a lot!

hehe, comics.com have a new 4 number code before their daily comics everyday and I wanted to use shell to get those comics and now i can

thanks again!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep question djgerbavore Linux - Newbie 3 11-04-2004 10:53 AM
Question about Grep irfanhab Linux - Newbie 6 08-23-2004 02:57 PM
grep question vasanthraghavan Programming 3 04-23-2004 12:32 AM
grep question keyops Programming 2 04-09-2004 09:17 PM
Quick grep question player_2 Linux - Software 2 10-10-2003 06:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration