1

I have a file with a lot of garbage(strange chars,comments,etc),the file contain some links which I want to extract with grep. File is really big,over 2000 words in one line. If I try this line works perfect with the exact match

egrep -Eo --text "abcde192848.bmp" Untitled\ 1.txt

Return correctly abcde192848.bmp. But there are a lot of bmp links and I cannot get it,if I try

egrep -Eo --text "^abc*+.bmp" Untitled\ 1.txt

Return nothing. My question is: how to grep from one line all strings which start with abc and end with bmp? The file is similar to this

***strangechars***urlabc1239.bmp****sstrangechars***urlabc394848.bmp***

The line is very big and contain a lot of .bmp "urls". The output I want must return

abc449048.bmp
abc231848.bmp
abc144848.bmp
2

Try

grep -o 'abc[a-z0-9]*\.bmp'
  • [a-z0-9]* this will match zero or more of lowercase alphabets and digits
  • \. this will match a . character literally


Why ^abc*+.bmp doesn't work

  • ^ is start of line anchor, so at best you can get one match per line, not all matches in the line
  • c* will match c zero or more times, perhaps you intended * to work like in shell glob?
  • + not sure what this would do in combination of *+
  • . will match any character, not just . character

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.