Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
removing find/replace .m3u is easy enough but I need to also remove the word live and one of the slashes besides it so I dont end up with double slashes //
This is what I attempted
Code:
update streams set stream_source = replace(stream_source, '/live/', '/');
update streams set stream_source = replace(stream_source, '.m3u8', '');
exit;
the .m3u8 is replaced with blank so that works but slash / is not replacing /live/
my understanding is that u cant search and replace slashes /
update streams set stream_source = replace(stream_source, 'live/', '');
Also, try your code and my try using double quotes.
And try escaping the slash.
[Confession: I did not know about the replace() function until now...very cool -- I don't have time to look it up right now...getting late here. ]
Although I will point out that a double slash is treated the same as a single slash, usually.
Code:
[root@localhost:~]# ls -l lqtest/testdir/
total 0
-rw-r--r-- 1 root root 0 Oct 26 23:42 file1
-rw-r--r-- 1 root root 0 Oct 26 23:42 file2
[root@localhost:~]# ls -l lqtest//testdir/
total 0
-rw-r--r-- 1 root root 0 Oct 26 23:42 file1
-rw-r--r-- 1 root root 0 Oct 26 23:42 file2
You could move the problem to bash level. I.e. write a shell script that uses mysql with the -e option to first obtain the URL, then processes it with the usual suspects sed and/or awk, finally update the record again with mysql -e.
The right most 3 bytes seems easy enough. replace(field_name) with left(FIELD_NAME, len(FIELD_NAME),3) ..
Next, to remove the word live that is obtained as the second element when the contents are SPLIT with forward slash as the delimiter. I am looking at using SPLIT with SUBSTRING_INDEX. I just googled and got this. https://coderwall.com/p/zzgo-w/split...ngs-with-mysql Does it help? Maybe SUBSTRING_INDEX - I didn't know about - can be used for the first part (last 3 bytes) also.
Alternatively, if it a small table (less rows) AND you can identify a unique field AND it's a one time job,
1. Dump out to a text file,
2. Change,
3. Update back.
You could move the problem to bash level. I.e. write a shell script that uses mysql with the -e option to first obtain the URL, then processes it with the usual suspects sed and/or awk, finally update the record again with mysql -e.
thanks berndbausch, I can barely write simple scripts. I dont think I can handle that one lol.
Quote:
Originally Posted by AnanthaP
The right most 3 bytes seems easy enough. replace(field_name) with left(FIELD_NAME, len(FIELD_NAME),3) ..
Next, to remove the word live that is obtained as the second element when the contents are SPLIT with forward slash as the delimiter. I am looking at using SPLIT with SUBSTRING_INDEX. I just googled and got this. https://coderwall.com/p/zzgo-w/split...ngs-with-mysql Does it help? Maybe SUBSTRING_INDEX - I didn't know about - can be used for the first part (last 3 bytes) also.
Alternatively, if it a small table (less rows) AND you can identify a unique field AND it's a one time job,
1. Dump out to a text file,
2. Change,
3. Update back.
OK
Thanks AnanthaP, I knew that was an option. I was afraid something would get changed or screwed up when I resave.
Quote:
Originally Posted by scasey
What about using double quotes?
Code:
mysql> update streams set stream_source = replace(stream_source, "live/", '');
Or escaping the slash?
Code:
mysql> update streams set stream_source = replace(stream_source, 'live\/', '');
mysql> update streams set stream_source = replace(stream_source, "live/", '');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql > update streams set stream_source = replace(stream_source, "live/", '')' at lin e 1
Should I use single quotes around the double quoutes or vice versa?
That query appears to have worked, except for the "0 rows afftected" part.
Try just
Code:
SELECT replace(stream_source, 'live/', '') FROM stream where stream_source like '%live%';
to test. It won't change anything in the database, just dump the output to the screen. A slash is not a special character, as far as I know. It shouldn't matter. Testing the replace() syntax without trying to change the database is where to start. IMO.
Quote:
Originally Posted by xray55
Code:
mysql> update streams set stream_source = replace(stream_source, "live/", '');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql> update streams set stream_source = replace(stream_source, "live/", '')' at line 1
That attempt appears to have included the mysql prompt (highlighted).
Did you try escaping the slash:
Code:
update streams set stream_source = replace(stream_source, 'live\/', '')
Quote:
Originally Posted by xray55
Should I use single quotes around the double quoutes or vice versa?
"live/"
'"live/"'
"'live/'"
Either double-quotes or escaping the slash should work, but again, test the replace syntax first with
The replace() function works just fine to remove slashes like this:
Code:
SELECT caption, replace(caption, '/', '') FROM `photos` WHERE caption like '%/%'
Of course, you don't want to remove all the slashes (nor did I in that example...I'd have messed up several records in my database). Once I get that query refined, I'll try your UPDATE SET.
Definitely want to pay attention to the WHERE clause...
Code:
SELECT caption, replace(caption, '/', '') FROM `photos` WHERE caption like '%in/%'
Modeling in/ New York for Barbizon -- 1943 Modeling in New York for Barbizon -- 1943
So the problem is not the slash...
UPDATE: Syntax using your UPDATE...SET logic worked just fine. That caption had the / removed from the only row that contained an '%in/%. The slash is not the problem with your syntax.
Do you (the user you're logged into mysql with) have UPDATE privileges on the table?
The replace() function works just fine to remove slashes like this:
Code:
SELECT caption, replace(caption, '/', '') FROM `photos` WHERE caption like '%/%'
UPDATE: Syntax using your UPDATE...SET logic worked just fine. That caption had the / removed from the only row that contained an '%in/%. The slash is not the problem with your syntax.
Do you (the user you're logged into mysql with) have UPDATE privileges on the table?
You have a MySQL user ‘root’?
Although in your OP you said that replacing the ‘. m3u8’ worked...so it must not be permissions...it was just a thought — an “is it plugged in?” question. Sorry.
Did you test what you’re trying with the SELECT…replace(…) syntax? What happened?
Again, the slash made no difference in my tests. There’s nothing special about a slash in that context.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.