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-18-2005, 07:56 AM   #1
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Rep: Reputation: 15
one more time about sed...


Oh F***

Could someone tell me what's wrong:

This line works perfectly: sudo sed -n "1p" ls_mpg

but this one: sudo sed -n "${i}p" ls_mpg

gives me one message: 'ed: -e expression n°1, caractère 2: commande inconnue: `

Which mean : unknown command

i=1

So it should give the same result no?
 
Old 05-18-2005, 08:40 AM   #2
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
i'm really losst this time... if someone can help me... i've long but i don't find what's wrong
 
Old 05-18-2005, 10:09 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I not tested but try (in bash) :
Code:
sudo eval "sed -n ${i}p ls_mpg"
 
Old 05-18-2005, 10:16 AM   #4
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
What is it done for? what should i see?
 
Old 05-18-2005, 10:20 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
What do you expect with your sed command ? What do you want to do ?
 
Old 05-18-2005, 10:23 AM   #6
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
lol that's right i should be more precise:

There is a file that contain name of files, like that:

File1
File2
File5
File4

And the first line print:

File1

And want the line that don't work to do the same work as the first one
 
Old 05-18-2005, 10:29 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Ok, what I understand is you want to extract line that matches a certain number

you could try :
Code:
eval "sed -n -e /$i/p ls_mpg"
or more simple with grep :
Code:
grep $i ls_mpg
 
Old 05-18-2005, 10:31 AM   #8
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
No i want to esxtract the line number five for example... but files have random names that could be 542859662521 or zfefge44g41erg7eeggg...

It can not refer to the content of the line
 
Old 05-18-2005, 10:35 AM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
So those lines don't work ?
Code:
sed -n -e ${i}p ls_mpg
# or
eval "sed -n -e ${i}p ls_mpg"
 
Old 05-18-2005, 10:38 AM   #10
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
i reboot under debian and i tell you that
 
Old 05-18-2005, 10:55 AM   #11
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
No it don't work , i get the same result as before...

must be a problem with the variable, but i do echo ${i} just before and i get "1"
 
Old 05-18-2005, 11:03 AM   #12
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Weird the code works perfectly on my system :
Code:
#!/bin/bash

i=1
sed -n -e ${i}p /etc/passwd
It outputs the first line of passwd file as expected
 
Old 05-18-2005, 11:12 AM   #13
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
Oh shit

So what could the problem be?

Any idea?
 
Old 05-18-2005, 11:21 AM   #14
orgazmo
Member
 
Registered: May 2005
Location: Paris, france
Posts: 53

Original Poster
Rep: Reputation: 15
#!/bin/bash

i=1
sed -n -e '${i}p' ls_mpg


i created essai that contains only these 3 lines...

and i get that : sed: -e expression n°1, caractère 0: `{' non refermée

Means '{' unclosed


 
Old 05-18-2005, 11:28 AM   #15
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Quoting is wrong.

From within a shell script you need to use " instead of '

This works (tried it):

Code:
#!/bin/bash

i=1
sed -n -e "${i}p" ls_mpg
Hope this helps.
 
  


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
Doub about `net time set` and daylight saving time Thakowbbery Linux - Software 0 10-17-2005 05:23 AM
ps2 mouse freezing on FC1/FC2 from time to time farpoint Linux - Hardware 5 08-14-2005 02:20 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
no signal when starting xorg for the 1st time (but the second time works fine) bungalowbill Linux - Software 0 06-04-2004 09:56 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

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

All times are GMT -5. The time now is 04:43 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