LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-12-2010, 01:49 PM   #1
koszta5
LQ Newbie
 
Registered: Dec 2010
Posts: 8

Rep: Reputation: 0
Post escaping double quotes in a file


Hi ,
I know it is pretty trivial but anyway...
I have php file that I am trying to read it looks like this

...
add_item_tabulky("Klaun-PF 2011","klaun_pf2011.jpg","","","");
add_item_tabulky("Prasátko-Šťastný celý_rok","prasatko_stastny_cely_rok.jpg","","","");
add_item_tabulky("Andílek na sáňkách","sanky.jpg","","","");
I dont*&^(^belong here
add_item_tabulky("Sněhulák","snehulak.jpg","","","");
add_item_tabulky("Stromeček-Veselé Vánoce","stromecek_vesele_vanoce.jpg","","","");
weird line
...

there are lines that begin with add_item_tabulky and also "weird lines" that dont begin with that...

now I need to echo both lines to a file but I need to transform the add_item_tabulky_line s first.

so I tried somehting like:

1 #!/bin/bash
2 while read line
3 do
4
5 if [[ "$line" =~ "add_item_tabulky(.*" ]]
6 then
7 echo $line
8 fi
9 done < $1


well bad news it has no output at all! Why is that? It is not the whole (rather complicated script but I just cant get this to work

What am i missin?
thnx
 
Old 12-12-2010, 01:56 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Try taking the . out. A bash pattern is not the same as a regular expression so . there means ' not "any character". You could also remove the * because the =~ operator matches anywhere in the line, not the whole line. If you want to anchor the pattern to the beginning of the line use ^. The quotes on the RHS of a =~ operator are taken as part of the pattern so are not needed (I'm a little hazy about this -- could be bash version dependent).

Putting those all together gives (not tested) if [[ "$line" =~ ^add_item_tabulky( ]]
 
1 members found this post helpful.
Old 12-12-2010, 02:16 PM   #3
koszta5
LQ Newbie
 
Registered: Dec 2010
Posts: 8

Original Poster
Rep: Reputation: 0
yeah thanks... I just didnt realize bash in fact doesnt natively support RE
 
Old 12-12-2010, 09:32 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Glad it worked. Patterns (actually filename expansion patterns that we use at the command line, hence the need to treat . as literal for the . .. and .* matches) defined here.

Threads can be marked SOLVED via Thread Tools.
 
  


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] Matching double quotes " hattori.hanzo Programming 7 11-24-2010 12:49 AM
Double Quotes Inside Double Quotes youarefunny Programming 6 06-09-2010 10:21 PM
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 04:44 PM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 05:50 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM

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

All times are GMT -5. The time now is 09:05 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