-1

I have a input / input file containing lines with urls like this

https://www.youtube.com/watch?v=VXw6OdVmMpw          Mon Nov 2 10:25:32 2015 
https://www.youtube.com/watch?v=VXw6OdVmMpw          Mon Nov 2 10:27:34 2015
https://www.youtube.com/watch?v=VXw6OdVmMpw          Mon Nov 2 10:28:23 2015

I want grep only they exact matched string like if i sed for the last line which is https://www.youtube.com/watch?v=VXw6OdVmMpw Mon Nov 2 10:28:23 2015

so it will delete the last line only Note : Lines may contain same text at front but different date and time so i need exact match , thanks for understanding .

2 Answers2

0

Do you just want to use the url at the beginning of line replace the whole line?
Two parts of regex in the command below:
1. Match the URL:

^([a-zA-Z0-9:/.?=]*)

  1. Match the last part:

.*

Then use the URL part replace the whole line.

echo "https://www.youtube.com/watch?v=VXw6OdVmMpw          Mon Nov 2 10:28:23 2015" | sed 's/^\([a-zA-Z0-9:/.?=]*\).*/\1/'

the result is

https://www.youtube.com/watch?v=VXw6OdVmMpw

Is this what you want?

enter image description here

android_su
  • 1,637
  • 4
  • 21
  • 30
  • With standard `echo` the result is not what you show. It's not clear how you expect this to solve the OP's question anyway (though the question is also so unclear that this might actually be a possible interpretation, although I don't see how to reach it). – tripleee Nov 02 '15 at 06:54
  • @tripleee I thought he want to use the url at the beginning of line replace the whole line. – android_su Nov 02 '15 at 07:17
  • @tripleee I think I am using the standard bash and echo. No alias on echo. Bash version GNU bash 4.3.11(1)-release (x86_64-pc-linux-gnu). – android_su Nov 02 '15 at 07:28
-2

required output can be achieved by using:

grep -v 'text to grep' 
arco444
  • 22,002
  • 12
  • 63
  • 67