LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2005, 08:06 AM   #1
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Rep: Reputation: 15
About sed


Hi all ;-)

Using this line in a shell script...

sed "s/.mp4//g" ls_mp4Temp > ls_mp4

... i get an error "sed: impossible de lire ls_mp4Temp: Aucun fichier ou répertoire de ce type"

which mean "sed: unable to read ls_mp4Temp: no such file or directory"

But the file exists!!! could someone tell me what could be wrong whith that?
 
Old 05-17-2005, 08:09 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
maybe put a ' pwd ' in the line just above the sed one to check your current
directory...

Also, I don't know if it matter, but try replace double quotes (") with single ones (')
in your sed expression
 
Old 05-17-2005, 08:22 AM   #3
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
Ok i checked with single quotes it does'nt work.

echo `pwd` gives me //root, thats the right place.

And if i dont do the > ls_MP4 but just "sed "s/.mp4//g" ls_mp4Temp" it works well but i want to redirect the result in a file !!!
 
Old 05-17-2005, 09:00 AM   #4
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
No idea?
 
Old 05-17-2005, 09:18 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Re-check your script, I am 99% sure that there is a human mistake somewhere
(or at least post your complete script, if it's not too big)
 
Old 05-17-2005, 09:31 AM   #6
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
#!/bin/bash
#03/05/05, clement benezech.

#Derniere mise a jour, 09/05/05

#Script de vérification des fichiers et de transcodage.

#Montage des lecteurs, a develloper. (necessaire?)

#Declaration des variables:

#
PATH=$PATH:/usr/local/bin

#
i=1

j=1

oui=0

#

echo "Transcodage en cours, veuillez patienter"

#

#Création des listes de fichiers.

#

rm ls_mpeg
rm ls_mp4Temp
rm ls_mp4
touch ls_mp4
#
ls /usr/local/Mpeg > ls_mpg

ls /usr/local/MP4 > ls_mp4Temp

#

#creation des rapports

#

touch rapport_sup

touch rapport_cre

#

#Suppression des extensions dans la liste

#
echo `pwd`

sed 's/.mp4//g' ls_mp4Temp > ls_mp4



here is the beginning, if you want more i could give it to you but what' is next do not work for the moment... it a really big script, and since it is my first one I am quite lost sometimes.
 
Old 05-17-2005, 10:48 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Try remove " touch ls_mp4 " line, the file will be created with the > redirection
 
Old 05-17-2005, 11:10 AM   #8
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
already done, in fact i added it to see if it could change something... but no result... thanks anyway

It seems that it don't work because i replace ".mp4" with nothing... it is not possible?

Is there a best way to do this?
 
Old 05-17-2005, 11:19 AM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Replacing something with nothing is perfectly valid and usual in sed

You could try editing the file "in place", that mean you do not need
to redirect output as sed work on the file itself (it use in fact a temp
file to do this, but it is hidden)

Try :
Code:
sed -i 's/.mp4//g' ls_mp4Temp
So all .mp4 instances will be removed from ls_mp4Temp file directly
 
Old 05-17-2005, 05:41 PM   #10
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
off the top of my head:
have you tried sed ... infile | cat > outfile ?
(that is, piping sed through cat (yay, the identity function!) before >'ing?)

just a thought,

Jonas
 
Old 05-19-2005, 09:21 AM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
sed -i 's/.mp4//g' ls_mp4Temp

The dot should be escaped if you want a literal dot removed:
sed 's/\.mp4//g' ls_mp4Temp

Other than that, it should work, because I tested this line myself:
>cat ls_mp4Temp
jschiwal@matrix:~/test> cat ls_mp4Temp
song1.mp4 song2.mp4
song3.mp4
jschiwal@matrix:~/test> sed 's/.mp4//g' ls_mp4Temp > ls_mp4
jschiwal@matrix:~/test> cat ls_mp4
song1 song2
song3
 
  


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
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Sed q? ky-lab_rat Linux - Software 5 10-26-2004 07:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Help with sed odious1 Linux - General 2 08-29-2003 10:52 AM
help with sed DavidPhillips Programming 3 08-11-2003 04:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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