![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grepping columns | ScKaSx | UNIX for Dummies Questions & Answers | 8 | 02-29-2008 06:44 PM |
| Grepping issue.. | LinuxRacr | Shell Programming and Scripting | 9 | 02-28-2008 12:26 PM |
| grepping around | cbeauty | Shell Programming and Scripting | 9 | 08-29-2007 02:56 AM |
| Grepping for strings | t4st33@mac.com | UNIX for Dummies Questions & Answers | 5 | 06-21-2007 12:51 AM |
| grepping for a sentence | eloquent99 | UNIX for Dummies Questions & Answers | 2 | 04-23-2003 03:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
grepping
The above is a possibility. However you'll only get the occurences where there are exactly the number of requested lines. If the requested string would be placed at the end of the file you would not see it. I should do the trick with a little script Code:
lnnr=10;
num_of_lines=10;
while read line
do
if (( $lnnr < $num_of_lines ))
then
echo $line
(( lnnr=$lnnr + 1 ))
else
echo $line | grep "string or whatever" >/dev/null 2>&1
if (( $?==0 ))
then
lnnr=0
echo $line
fi
fi
done < inputfile
![]() I added code tags for readability -- Perderabo Last edited by Perderabo; 04-22-2003 at 11:17 AM.. |
|
|||||
|
tail -10 and head -10 print out the first 10 lines and last 10 lines, respectively, of a file. They cannot be used to pull lines from the middle of a file. Plus what you've done will output one or more lines containing the word "word" and then try to feed those lines into the tail or head command, which actually needs a filename.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|