![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Replacing Last occurance of & from a string | vivekshady | Shell Programming and Scripting | 1 | 05-13-2008 08:15 PM |
| search for a word and it's occurance at the output | legendofanatoli | UNIX for Dummies Questions & Answers | 2 | 05-05-2008 04:52 PM |
| count string occurance in a file hourly | ayhanne | UNIX for Dummies Questions & Answers | 2 | 10-13-2007 10:47 AM |
| Unix find command to print directory and search string | princein | UNIX for Dummies Questions & Answers | 4 | 03-06-2007 08:46 AM |
| Removing the last occurance of string | dkhanna01 | Shell Programming and Scripting | 7 | 12-28-2004 05:46 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
String search - Command to find second occurance
Hi,
I am new to Unix world. Is there any command which can directly return the second occurance of a particular string in a file? Basically, I want to read the contents of the file from the second occurance of a particualr string. Can be implemented using a loop, but am just wondering if there is a command which can help me do so. Please let me know. TIA Saurabh |
|
||||
|
Other than looping or using awk, perl, or python, I have no other idea except an extreme hack like this:
Code:
#!/bin/ksh # total line in file wc -l inputfile | read filelen dummy # find the line to start reading on grep -n 'some string' inputfile | head -n 2 | tail -n 1 | read startline dummy # subtract start line from total length=$(( $filelen - $startline )) # tail the lines you need. tail -n $length inputfile It wastes resources anyway, because it reads thru the file several times. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|