Hello Experts,
Sample.txt:
1#Cooker#Philips#NoCostEMI#Available
2#Cooker#Bajaj#NoCostEMI#Available
3#Cooker#Prestige#NoEMI#Available
4#Cooker#PP#NoCostEMI#OutOfStock
5#Purifier#Philips#NoCostEMI#Available
I need to print (using sed) details of Cooker which are Available.
I tried the following code:
sed -n '/Cooker/,/Available/p' Sample.txt
But I am not getting the desired result
I am using BASH shell.
Could you please help.
Thank you.
Neo
2
This would be easy with grep
grep Cooker Sample.txt | grep Available
Thank you.
I am aware of using grep in order to achieve the desired result.
However, I wished to try it using sed.
Could you please let me know how this can be done using sed.
Hi
sed '/Cooker.*Available$/!d' Sample.txt
But as @Neo showed 'grep' here is the best option
You can change a little
grep 'Cooker.*Available$' Sample.txt
--- Post updated at 19:21 ---
More options
sed -nr 's/.*Cooker#(.*)#Available$/\1/p' Sample.txt
grep -oP 'Cooker#\K.*(?=#Available$)' Sample.txt