PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > linux.debian.user > doubt in using sed
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
linux.debian.user debian-user@lists.debian.org.

doubt in using sed

Réponse
 
LinkBack Outils de la discussion
Vieux 09/03/2007, 23h10   #1
L.V.Gandhi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut doubt in using sed

I have made a script like this as test1
#!/bin/bash
line="3IINFOTECH,20050422000000,118,118,96,98.1,82 60440"
olds=$(echo "$line"|cut -d, -f2)
echo $olds
da=${olds:0:8}
echo $da
echo "$line" > temp1
sed -e 's/$olds/$da/' temp1 >>temp
cat temp1
cat temp
When I run get as
lvgandhi@lvgdell600m:~/.qtstalker/data0/export$ test1
20050422000000
20050422
3IINFOTECH,20050422000000,118,118,96,98.1,8260440
3IINFOTECH,20050422000000,118,118,96,98.1,8260440
I don't find any replacement. Where am I wrong? what should be done to get
the replacement done?
--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042

  Réponse avec citation
Vieux 09/03/2007, 23h20   #2
Mathias Brodala
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: doubt in using sed

Hello.

L.V.Gandhi, 10.03.2007 00:01:
> I have made a script like this as test1
> #!/bin/bash
> line="3IINFOTECH,20050422000000,118,118,96,98.1,82 60440"
> olds=$(echo "$line"|cut -d, -f2)
> echo $olds
> da=${olds:0:8}
> echo $da
> echo "$line" > temp1
> sed -e 's/$olds/$da/' temp1 >>temp


You want to use double quotes here so that the shell can expand the variables.


Regards, Mathias

--
debian/rules


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF8enIYfUFJ3ewsJgRAp1BAKCaoWuYnrwGK/DELIA+mkfs/o3MDQCfYJKH
84eERXlwMqj/uaWoeEr4cDc=
=ANWm
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 09/03/2007, 23h20   #3
David Clymer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: doubt in using sed

On Fri, 2007-03-09 at 15:01 -0800, L.V.Gandhi wrote:
> I have made a script like this as test1
> #!/bin/bash
> line="3IINFOTECH,20050422000000,118,118,96,98.1,82 60440"
> olds=$(echo "$line"|cut -d, -f2)
> echo $olds
> da=${olds:0:8}
> echo $da
> echo "$line" > temp1
> sed -e 's/$olds/$da/' temp1 >>temp
> cat temp1
> cat temp
> When I run get as
> lvgandhi@lvgdell600m:~/.qtstalker/data0/export$ test1
> 20050422000000
> 20050422
> 3IINFOTECH,20050422000000,118,118,96, 98.1,8260440
> 3IINFOTECH,20050422000000,118,118,96,98.1,8260440
> I don't find any replacement. Where am I wrong? what should be done to
> get the replacement done?


The problem is that you've used single quotes, preventing shell
expansion of your variables. Try:

sed -e "s/$olds/$da/" temp1 >>temp

My guess is that will work for you.

-davidc

--
gpg-key: http://www.zettazebra.com/files/key.gpg

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBF8euB2XpGgG+SNaERAqtEAJ4vB2Tt2Zda89IpsmLlQ9 z8el7toQCgrfpH
Ac1e4jQbo35vde3iEJotcwY=
=jUIM
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 10/03/2007, 11h20   #4
Mathias Brodala
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: doubt in using sed

Hello.

Please reply to the list.

L.V.Gandhi, 10.03.2007 05:24:
> In another similar one I have problem
>
> lvgandhi@lvgdell600m:~/stock/datafiles$ ls -l nse2/
> total 0
> lvgandhi@lvgdell600m:~/stock/datafiles$ ls -l 3IINFOTECH
> -rw-r--r-- 1 lvgandhi lvgandhi 23400 2007-03-09 15:47 3IINFOTECH
> lvgandhi@lvgdell600m:~/stock/datafiles$ sed -e "s/3IINFOTECH,//" 3IINFOTECH
> |less
> lvgandhi@lvgdell600m:~/stock/datafiles$ sed -e "s/3IINFOTECH,//" 3IINFOTECH
>> /home/lvgandhi/stock/datafile/nse2/3IINFOTECH

> bash: /home/lvgandhi/stock/datafile/nse2/3IINFOTECH: No such file or
> directory
> In sed -e "s/3IINFOTECH,//" 3IINFOTECH |less I could see the correct
> output.
> But when I redirect, as in next command I get error "bash:
> /home/lvgandhi/stock/datafile/nse2/3IINFOTECH: No such file or directory"
> Redirecting to a file in same folder works.
> ie sed -e "s/3IINFOTECH,//" 3IINFOTECH > temp works.
> Any explanation please


You forgot a 's': 'datafiles' vs. 'datafile'.


Regards, Mathias

--
debian/rules


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF8pKSYfUFJ3ewsJgRApAJAJ92xpKMf+hp/Pi9rva0HY0dw9EA4wCdGP81
l0NB9kg478OWYl61UpIN0gk=
=BvhP
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 10/03/2007, 14h50   #5
L.V.Gandhi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: doubt in using sed

On 3/9/07, David Clymer <david@zettazebra.com> wrote:
>
> On Fri, 2007-03-09 at 20:22 -0800, L.V.Gandhi wrote:
> >
> >
> > Thanks David and Mathias.
> > In the above example after double quotes it works. When I pass the
> > output to file it works.
> > In another similar one I have problem

>
> You're welcome. Please send this question to the list, and I'll take a
> whack at answering it. Following up off-list is lousy nettiquette. The
> list is your resource, not me personally.
>
> -davidc
>

Mr.David, Sorry for personal mail. Thanks for your efforts.


--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042

  Réponse avec citation
Vieux 10/03/2007, 14h50   #6
L.V.Gandhi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: doubt in using sed

On 3/10/07, Mathias Brodala <info@noctus.net> wrote:
>
> Hello.
>
> Please reply to the list.
>
> L.V.Gandhi, 10.03.2007 05:24:
> > In another similar one I have problem
> >
> > lvgandhi@lvgdell600m:~/stock/datafiles$ ls -l nse2/
> > total 0
> > lvgandhi@lvgdell600m:~/stock/datafiles$ ls -l 3IINFOTECH
> > -rw-r--r-- 1 lvgandhi lvgandhi 23400 2007-03-09 15:47 3IINFOTECH
> > lvgandhi@lvgdell600m:~/stock/datafiles$ sed -e "s/3IINFOTECH,//"

> 3IINFOTECH
> > |less
> > lvgandhi@lvgdell600m:~/stock/datafiles$ sed -e "s/3IINFOTECH,//"

> 3IINFOTECH
> >> /home/lvgandhi/stock/datafile/nse2/3IINFOTECH

> > bash: /home/lvgandhi/stock/datafile/nse2/3IINFOTECH: No such file or
> > directory
> > In sed -e "s/3IINFOTECH,//" 3IINFOTECH |less I could see the correct
> > output.
> > But when I redirect, as in next command I get error "bash:
> > /home/lvgandhi/stock/datafile/nse2/3IINFOTECH: No such file or

> directory"
> > Redirecting to a file in same folder works.
> > ie sed -e "s/3IINFOTECH,//" 3IINFOTECH > temp works.
> > Any explanation please

>
> You forgot a 's': 'datafiles' vs. 'datafile'.
>
>
> Regards, Mathias
>

Thanks.


--
L.V.Gandhi
http://lvgandhi.tripod.com/
linux user No.205042

  Réponse avec citation
Vieux 27/03/2007, 16h10   #7
Michelle Konzack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: doubt in using sed

Am 2007-03-09 15:01:51, schrieb L.V.Gandhi:
> I have made a script like this as test1
> #!/bin/bash
> line="3IINFOTECH,20050422000000,118,118,96,98.1,82 60440"
> olds=$(echo "$line"|cut -d, -f2)
> echo $olds
> da=${olds:0:8}
> echo $da
> echo "$line" > temp1
> sed -e 's/$olds/$da/' temp1 >>temp

^ ^
sed -e "s/$olds/$da/" temp1 >>temp

> cat temp1
> cat temp


Thanks, Greetings and nice Day
Michelle Konzack
Systemadministrator
Tamay Dogan Network
Debian GNU/Linux Consultant


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
50, rue de Soultz MSN LinuxMichi
0033/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFGCTBoC0FPBMSS+BIRApk8AJwJb6wVAJ1qwJ5mxF4CAs/ayJsm/ACfRnfB
8zfWZ75+LC0K8+7nb4BXXT4=
=9BK9
-----END PGP SIGNATURE-----

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13304 seconds with 15 queries