![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| forums to hire unix experts | itmgr | Shell Programming and Scripting | 3 | 05-08-2007 07:06 PM |
| Calling All Aix Experts | Courtney3216 | AIX | 0 | 03-17-2006 05:30 PM |
| Shell Coding question for any experts out there | dfran1972 | Shell Programming and Scripting | 4 | 01-12-2004 06:04 AM |
| Help from lint experts needed | amatsaka | High Level Programming | 2 | 03-29-2002 05:42 AM |
| Experts Only! Hard Question Ahead!!!! | Foo49272 | UNIX for Advanced & Expert Users | 1 | 01-07-2002 07:22 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help - from awk, sed experts
Hi ,
I have a file as below. Contents of the file are -------------------- aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa bbbbbbbbbbb ccccccccccc ddddddddddd aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa bbbbbbbbbbb ccccccccccc ddddddddddd aaaaaaaaaaa I want to do the follwing if exists "ccccccccccc" get "bbbbbbbbbbb" "ccccccccccc" "ddddddddddd" fi Can someone help me in doing this using awk/sed.. thanks srini |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Hard to do with sed, but this seems to work on HP-UX. The script needs one arg which string to find.
Code:
#! /usr/bin/ksh sed -n -e ":l" -e "h;n;s/$1/$1/;t m" -e "b l" -e ":m" -e "H;n;H;g;p" exit 0 |
|
#3
|
|||
|
|||
|
Hi Perderabo,
will it work in Linux .. can you please let me know , how to run this . Assumig file name is abc.txt and the search string is "ccccccc" is it correct ./script.sh abc.txt Thanks Srini |
|
#4
|
||||
|
||||
|
./script.ksh ccccccccc < abc.txt
EDIT: On linux, you may not have /usr/bin/ksh. I think it should work with bash. Change first line to a shell you have #! /bin/bash or whatever. |
|
#5
|
|||
|
|||
|
Hi Perderabo,
It works fine . But can you please explain me what exactly happening here , sed -n -e ":l" -e "h;n;s/$1/$1/;t m" -e "b l" -e ":m" -e "H;n;H;g;p" and what if, if I want to get 3 lines before the search string and one line after the search string . i.e aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa kkkkkkkkkkk llllllllllllllllllllllllll tttttttttttttt bbbbbbbbbbb ccccccccccc ddddddddddd aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaa kkkkkkkkkkk llllllllllllllllllllllllll tttttttttttttt bbbbbbbbbbb ccccccccccc ddddddddddd aaaaaaaaaaa aaaaaaaaaaa kkkkkkkkkkk llllllllllllllllllllllllll tttttttttttttt bbbbbbbbbbb ccccccccccc ddddddddddd aaaaaaaaaaa Thanks srini |
|||
| Google The UNIX and Linux Forums |