![]() |
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 Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep problem with the ^ symbol, help needed please. | Gvsumrb | UNIX for Dummies Questions & Answers | 2 | 03-31-2008 10:04 AM |
| SED command ---------help needed | veerapureddy | Shell Programming and Scripting | 4 | 03-17-2008 05:12 PM |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-05-2007 02:59 AM |
| Help with tail /grep needed | Felix2511 | UNIX for Dummies Questions & Answers | 4 | 05-17-2007 03:22 PM |
| help needed for sed command | manualvin | UNIX for Dummies Questions & Answers | 2 | 06-24-2004 11:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help Needed in Grep Command
Hi
i am using grep command to search a string in a file and i am able to find that string in it .. but moving forward once i find the string i need to remove the 5 lines above that and to remove 2 lines below it .. Just wanted to be clear there should be no lines existing which has a string coys11 Example : file1.txt cat435 gggte werwr coys11 ewrer when i run this script , it should delete all the lines above it and lines below it Thanks.. Please do help me on this .. Thanks again..!! |
|
||||
|
Help Needed in Grep Command
Hi
i am using grep command to search a string in a file and i am able to find that string in it .. but moving forward once i find the string i need to remove the 5 lines above that and to remove 2 lines below it .. Just wanted to be clear there should be no lines existing which has a string coys11 Example : file1.txt cat435 gggte werwr coys11 ewrer when i run this script , it should delete all the lines above it and lines below it Thanks.. Please do help me on this .. Thanks again..!! |
|
||||
|
Quote:
if he just want to remove just coys11 grep -v -w joys11 inpufile is better. But I thing he wants something else |
|
||||
|
let's say your file looks like this;
. . . aa bb cc dd ee ff gg hh ii jj kk . . and let's say your string is gg do you want to remove bb-ii (including bb,gg,ii) ? if it is; currentline=`grep -n string inputfile|awk ' {print $1} '` let "startingline=$currentline-5" let "finishingline=$currentline+2" sed -n "$startingline,${finishingline}!s/.*/&/p" inputfile>outfile |
|
||||
|
Hi
Thanks for the replies Just wanted to be clear lets assume i have a file1.txt which has the following aaa bbb bbb ccc qqq 343 454 eee i am looking for a string 343 once the script finds 343 it should delete 4 lines above it and 2 lines below it the output file should be qqq Thanks |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|