LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:18 AM   #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 11:22 AM.
 
Old 02-14-2013, 11:24 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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, 11:40 AM   #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, 11:43 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
@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, 11:49 AM   #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, 11:51 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 12: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, 12:02 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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



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 11:50 AM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
[SOLVED] action on unmatched pattern - awk sopier Programming 5 12-13-2011 07:31 PM
[SOLVED] grep [A-Z] returns unmatched lines MrDetail Linux - Newbie 13 02-22-2011 01:06 AM
grep: Unmatched [ or [^ sank1800 Linux - Newbie 6 04-29-2009 08:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:09 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
Open Source Consulting | Domain Registration