LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-14-2013, 12:18 PM   #1
1Volt
LQ Newbie
 
Registered: Jun 2011
Posts: 13

Rep: Reputation: Disabled
grep unmatched [ or [^


Welcome ;


i got a text file contain images urls like

PHP Code:
<img id="thumb-m6qsZ" class="thumb-title" title="" alt="" data-src="http://domain.com/m6qsZs.jpg" data-index="0" />
<
img id="thumb-KwvJK" class="thumb-title" title="" alt="" data-src="http://domain.com/KwvJKs.jpg" data-index="1" /> 
how can i get the urls that's start with http:// and ends with .jpg and save them in another text file which will be every url in a new line . Like this :

Code:
http://domain.com/m6qsZs.jpg
http://domain.com/KwvJKs.jpg
i tried : grep -i "/http.[^"]*\.jpg/" i.txt > o.txt

but see what i get :

user@user ~
$ grep -i "/http.[^"]*\.jpg/" "i.txt" > "o.txt"
> #when i press enter i get a new line says " > " again
>
>
> " #when i put " i get
grep: Unmatched [ or [^



how can i do it ?

Last edited by 1Volt; 02-14-2013 at 12:22 PM.
 
Old 02-14-2013, 12:24 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Use apostrophe (') instead of the ".

the problem with the $ grep -i "grep -i "/http.[^"]*\.jpg/" "i.txt" > "o.txt" is the string identification.

Start with the first " and go to the next occurrence... and you see a syntax error.

The command should be:
grep -i '/http.[^"]*\.jpg\"' i.txt > o.txt

Now all " characters are contained within an apostrophe quote (') which will not be interpreted by the shell.
 
1 members found this post helpful.
Old 02-14-2013, 12:40 PM   #3
1Volt
LQ Newbie
 
Registered: Jun 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Use apostrophe (') instead of the ".

the problem with the $ grep -i "grep -i "/http.[^"]*\.jpg/" "i.txt" > "o.txt" is the string identification.

Start with the first " and go to the next occurrence... and you see a syntax error.

The command should be:
grep -i '/http.[^"]*\.jpg\"' i.txt > o.txt

Now all " characters are contained within an apostrophe quote (') which will not be interpreted by the shell.
Thank You , No errors but the file is empty no urls in
could u help me with this
plus a note: that i just copied the command i don't understand it
so please gimme a full solution based on my question .
 
Old 02-14-2013, 12:43 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@1Volt: Your code would still print the complete line when a hit is found.

Have a look at grep's -o option:
Code:
grep -io "http://.*\.jpg" i.txt > o.txt
 
1 members found this post helpful.
Old 02-14-2013, 12:49 PM   #5
1Volt
LQ Newbie
 
Registered: Jun 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
@1Volt: Your code would still print the complete line when a hit is found.

Have a look at grep's -o option:
Code:
grep -io "http://.*\.jpg" i.txt > o.txt

Thank You , it works but not every url in a new line
 
Old 02-14-2013, 12:51 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by 1Volt View Post
Thank You , it works but not every url in a new line
Post a _relevant_ example of your infile.
 
1 members found this post helpful.
Old 02-14-2013, 01:00 PM   #7
1Volt
LQ Newbie
 
Registered: Jun 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
Post a _relevant_ example of your infile.
Ops i'm very sorry
cuz i was using Cygwin in windows and i opened the file with notepad
and as u know the text format between win&linux is different
with notepad++ the lines comes correctly thank you very much
 
Old 02-14-2013, 01:02 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by 1Volt View Post
Ops i'm very sorry
cuz i was using Cygwin in windows and i opened the file with notepad
and as u know the text format between win&linux is different
with notepad++ the lines comes correctly thank you very much
No problem


Can you put up the [SOLVED] tag.
- above the first post -> Please Mark this thread as solved if you feel a solution has been provided.
- -or- -
- first post -> Thread Tools -> Mark this thread as solved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Error while using awk: Unmatched '. shivaa Linux - Newbie 3 12-14-2012 12:50 PM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 03:07 PM
[SOLVED] action on unmatched pattern - awk sopier Programming 5 12-13-2011 08:31 PM
[SOLVED] grep [A-Z] returns unmatched lines MrDetail Linux - Newbie 13 02-22-2011 02:06 AM
grep: Unmatched [ or [^ sank1800 Linux - Newbie 6 04-29-2009 09:39 AM


All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration