Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-12-2010, 04:55 PM   #1
LQ Newbie
Registered: Dec 2010
Posts: 8

Rep: Reputation: 0
bash giving me trouble again

Sorry to be a pain twice a day

I read a file line by line (lines are
add_item_tabulky("Prasátko-Šťastný nový rok","prasatko_stastny_novy_rok.jpg","","","");
add_item_tabulky("Svatá rodina","rodina.jpg","","","");
add_item_tabulky("Sněhulák před domem","snehulak2.jpg","","","");

and when I want to replace a part of the line it isnt working!

while read line
line=$line|sed "s/\");//"
echo $line
done << file.php
I would expect the result to be :
add_item_tabulky("Sněhulák před domem","snehulak2.jpg","","","
(missing the "): in the end... but it doesnt happen.. Why is that?

the line doesnt get changed... I am guessing it has something to do with double quotes cause when I do

echo "\"\");"|sed "s/\");//"
the result is (as I expect)--> "
I tried doing echo $line|sed "s/\");//" but it dies with command not found (the quotes arent escaped and echo cant handle it)

thanks for help
Old 12-12-2010, 05:35 PM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Try (untested):

line=$(echo $line | sed "s/\");//")
Old 12-12-2010, 06:00 PM   #3
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
The double input redirection << is the syntax for here documents so that the shell expect some text terminated by the keyword following <<. Said that, you can simply try parameter substitution as in:
while read line
  echo ${line/\");/}
done < file.php
or eventually use single quotes to embed the sed command and avoid confusion:
while read line
  line=$(echo $line | sed 's/");//')
  echo $line
done < file.php
Old 12-12-2010, 06:10 PM   #4
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
And now for something completely different.

Section entitled:

Deletes longest match of $substring from back of $string.
I got this modified version of the program to work ... finally.

while read line
echo line is $line
echo line2 is $line2
done < test.tmp
Note that my test.tmp has only got one line of data.

@koszta5: I started working on your problem as soon as it appeared in LQ spy with no replies so I worked on it for 1 hour and 15 minutes. I struggled with sed for a long time. Then I looked up string manipulation on Google. It showed me the link at TLDP. A little reading, a little experimenting, and I got it. The documentation is a bit confusing because they show two percent signs in the function but it only wants one percent sign between the parameters. The example code on that page set me straight.

Moral: Don't give up but do look at alternative approaches to solving a problem.

Last edited by stress_junkie; 12-12-2010 at 06:26 PM.


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] Bash function syntax giving trouble luvshines Programming 6 09-19-2010 06:29 AM
Smart is giving me trouble! BarfBag SUSE / openSUSE 2 09-19-2006 12:15 PM
totem is giving me trouble. Lokathor Debian 0 05-31-2006 11:38 PM
Trying to get 1280x1024 but X is giving me trouble. ooagentbender Linux - Newbie 3 05-17-2004 10:42 PM
ProFTPD giving me trouble. freakydude Mandriva 2 08-31-2003 05:47 PM

All times are GMT -5. The time now is 09:42 AM.

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