-   Linux - Newbie (
-   -   escaping double quotes in a file (

koszta5 12-12-2010 02:49 PM

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("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
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?

catkin 12-12-2010 02:56 PM

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( ]]

koszta5 12-12-2010 03:16 PM

yeah thanks... I just didnt realize bash in fact doesnt natively support RE

catkin 12-12-2010 10:32 PM

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.

All times are GMT -5. The time now is 12:03 PM.