LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 12-12-2010, 03:55 PM   #1
koszta5
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!
->


Code:
while read line
do
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

Code:
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, 04:35 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,716

Rep: Reputation: 634Reputation: 634Reputation: 634Reputation: 634Reputation: 634Reputation: 634
Try (untested):

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

Rep: Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909
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:
Code:
while read line
do
  echo ${line/\");/}
done < file.php
or eventually use single quotes to embed the sed command and avoid confusion:
Code:
while read line
do
  line=$(echo $line | sed 's/");//')
  echo $line
done < file.php
 
Old 12-12-2010, 05:10 PM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

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

http://tldp.org/LDP/abs/html/string-manipulation.html

Section entitled:
Quote:
${string%%substring}

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

Code:
while read line
do
line2=${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 05:26 PM.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash function syntax giving trouble luvshines Programming 6 09-19-2010 05:29 AM
Smart is giving me trouble! BarfBag Suse/Novell 2 09-19-2006 11:15 AM
totem is giving me trouble. Lokathor Debian 0 05-31-2006 10:38 PM
Trying to get 1280x1024 but X is giving me trouble. ooagentbender Linux - Newbie 3 05-17-2004 09:42 PM
ProFTPD giving me trouble. freakydude Mandriva 2 08-31-2003 04:47 PM


All times are GMT -5. The time now is 11:13 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration