Hi,
I am facing difficulties in selecting the contents between two delimiters when there is a new line occurs..
Eg:
>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 %
```[/b]
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 .
```text
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.
:-)
code
nawk '1' ORS=" " file.txt | nawk '{print $4}' FS="--|%"
the above code will print :-
"this is the second line and not able to print" in one line.
BR
try:
# sed -n '/efgh/,/%/{s/efgh-- //;s/%//;p;}' sample.txt
this is the
second line and not
able to print
HTH
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 ----------
#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
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.
code
nawk '1' ORS=" " input_file | nawk '{print $2,$4,$6}' OFS="\n" FS="--|%" > output_file
more input_file:-
abcd -- this is the first line %
efgh-- this is the
second line and not
able to print %
ijkl -- this is the 3rd line %
more output_file:-
this is the first line
this is the second line and not able to print
this is the 3rd line
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 . ?
Why don't you try something for yourself with all the the solutions given to you?
This is not a helpdesk service, we're not here to do your work for you.
code:
nawk -v RS="%\n" -v FS="--" '/pattern you look for/{print $2}' input_file > output_file
I hope this will satisfy you.
BR
ahmad thank u very much..