![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| string deletion, variable contents, fixed delimiters | rebelbuttmunch | Shell Programming and Scripting | 2 | 03-24-2009 07:44 AM |
| script not working...select utility | mobydick | Shell Programming and Scripting | 6 | 05-08-2008 07:33 AM |
| Encountered error! | puspendu | UNIX Benchmarks | 0 | 09-07-2006 05:37 AM |
| Newline character not working for ksh | sanikv | Shell Programming and Scripting | 11 | 06-23-2005 02:34 PM |
| 554 Unallowed chars encountered | abibbens | UNIX for Advanced & Expert Users | 1 | 01-29-2002 01:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
select contents between two delimiters (not working if newline in encountered)
Hi, I am facing difficulties in selecting the contents between two delimiters when there is a new line occurs.. Eg: Code:
>more sample.txt abcd -- this is the first line % efgh-- this is the second line and not able to print % ijkl -- this is the 3rd line % when i search for abcd and use the below command , i am able to print the desired contents between '--' and '%'. But the same i am not able to print in the case of 'efgh' . Its only printing the 1st line of that word found. pls tell me what correction to be included in this code.. or suggest me the code for this . Code:
grep -w efgh sample.txt | awk -F"-" '{print $2}' | awk -F"||" '{print $1}'
Required output : this is the second line and not able to print thanks in advance. :-)
Last edited by Balaji PK; 11-02-2009 at 05:46 AM.. Reason: code tags, please... |
|
||||
|
This is fine.. but i want it generalised. I mean i should be able to give input text to it.. ---------- Post updated at 05:10 AM ---------- Previous update was at 05:08 AM ---------- Code:
#sed -n '/efgh/,/%/{s/efgh-- //;s/%//;p;}' sample.txt
This gives the desired output for that 'efgh' But does not give correct output for 'abcd'.. pls suggest Code:
sed -n '/abcd/,/%/{s/efgh-- //;s/%//;p;}' sample.txt
abcd -- this is the first line
this is the
second line and not
able to print
[KRYPTON]/appltgb/test/repc/balaji >
---------- Post updated at 05:23 AM ---------- Previous update was at 05:10 AM ---------- can u pls suggest a generalised code for the problem stated above. Last edited by pludi; 11-02-2009 at 06:16 AM.. Reason: code tags, please... |
|
||||
|
well this is good. But when i change the input file ,,i mean if i insert two more lines..it will not work..pls suggest a code that will help me even if i change the input file. the objecive is to give a input file , a word to search in it. once the word found then print the contents corresponding to the word from '--' to '%' and stop.
Am i clear . ? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|