LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 03-09-2012, 09:41 AM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191

If using variables you will need to use double quotes instead of single.
 
Old 03-09-2012, 03:52 PM   #17
tastiero
LQ Newbie
 
Registered: Mar 2012
Location: Rome (Italy)
Posts: 17

Original Poster
Rep: Reputation: Disabled
yes but the problem is the same. in the variable there are / cause is a web link
and i have back only error. i don't know what's wrong cause i'm new about sed and
script in general.
pls help.
thanks
 
Old 03-10-2012, 01:46 AM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please show what you are assigning to the variable?
 
Old 03-10-2012, 02:23 AM   #19
tastiero
LQ Newbie
 
Registered: Mar 2012
Location: Rome (Italy)
Posts: 17

Original Poster
Rep: Reputation: Disabled
i have to insert
http://update.mysite.com/softw/12release/update/ at the starts of each line before the filename
(e.g. http://update.mysite.com/softw/12rel...3r8rheuwir.cfg)
i use this script
sed 's/^/http:\/\/update.mysite.com\/\softw*12release*update*/' list.txt
where list.txt contains a list of files like this:

........
x4er4lsc_920d904bz.cfg
x4er4lsc_920d905bz.cfg
x4er4lsc_920d906bz.cfg
x4er4lsc_920d907bz.cfg
x4er4lsc_920d908bz.cfg
x4er4lsc_920d909bz.cfg
x4er4lsc_920d910bz.cfg
x4er4lsc_920d911bz.cfg
x4er4lsc_920d912bz.cfg
x4er4lsc_920d913bz.cfg
........

no problems until the slash is followed by "number" or "u" or "a".
how can i resolve?
temporally i change the slash substitution between each fields with asterisk "*"
e.g http://update.mysite.com/softw*12rel...4c_920d9bz.cfg
and then manually by kate editor replace "*" with "/".
i resolve temporally but i desire that this action will be automatic.
what's wrong?
 
Old 03-10-2012, 05:32 AM   #20
tastiero
LQ Newbie
 
Registered: Mar 2012
Location: Rome (Italy)
Posts: 17

Original Poster
Rep: Reputation: Disabled
i try

URL='http://update.mysite.com/softw/12release/update/'

sed "s/^/$ADRS/g" infoavi.txt

return the error

sed: -e expression #1, char 11: unknown option to `s'

how can i pass variable to sed?
 
Old 03-10-2012, 05:46 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Ahhh ... but of course if you are saying "/" is the separator then as soon as it hits the next one it will stop, however, sed allows for this, so try:
Code:
sed "s@^@$ADRS@g" infoavi.txt
This of course assumes that the symbol @ is not in the variable either
 
1 members found this post helpful.
Old 03-10-2012, 05:53 AM   #22
tastiero
LQ Newbie
 
Registered: Mar 2012
Location: Rome (Italy)
Posts: 17

Original Poster
Rep: Reputation: Disabled
B I N G O ! ! ! ! ! ! !

i try many times and search on the web, piece by piece and test by test i found what that i want.

URL="http:\/\/update.mysite.com\/\softw\/12release\/update\/"

sed "s/^/$URL/g" list.txt

results ok

........
http://update.mysite.com/softw/12rel..._920d918bz.cfg
........

only one question. if you look at the web url, the word "update", if change in with other word like "group" i need to add a backslash before letter "g".
what's the difference?
i see that's difference also if i use numbers. why?
thank you for cooperation.
 
Old 03-10-2012, 07:35 AM   #23
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
tastiero, please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.


Don't bother trying to backslash-escape the contents of the variable itself. Trying to do such generally only leads to frustration.

As grail mentioned, you don't have to use "/" as the sed "s" command delimiter; just about any ascii character can be substituted instead. Simply choose one that isn't found in the string itself.

grail used "@" above, but I personally like to use "|" myself most of the time.

Code:
URL="http://update.mysite.com/softw/12release/update/"

sed "s|^|$URL|" list.txt

Edit: BTW, since "^" can only match once per line, the "g" (global) modifier isn't necessary here. You only need to use it when doing multiple replacements on a single line.

Last edited by David the H.; 03-10-2012 at 07:44 AM. Reason: as stated
 
1 members found this post helpful.
Old 03-10-2012, 08:10 AM   #24
tastiero
LQ Newbie
 
Registered: Mar 2012
Location: Rome (Italy)
Posts: 17

Original Poster
Rep: Reputation: Disabled
thanks david and grail
i try as soon as possible and let you know

Last edited by tastiero; 03-10-2012 at 08:33 AM.
 
Old 03-12-2012, 03:16 AM   #25
tastiero
LQ Newbie
 
Registered: Mar 2012
Location: Rome (Italy)
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thanks david, it works fine like i want.
i hope to exchange problems and solution again.
thanks to all that help me.
 
Old 03-12-2012, 04:00 AM   #26
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please remember to mark as SOLVED once you have a solution
 
Old 03-12-2012, 04:10 AM   #27
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Good to hear it. Please mark the thread as solved.

(D'oh. Beaten by grail. )

Last edited by David the H.; 03-12-2012 at 04:11 AM. Reason: too slow!
 
  


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
[SOLVED] Extract a substring using regular expression with SED PenguinJr Programming 9 05-11-2011 12:47 PM
Extract substring using sed hweontey Linux - Newbie 1 02-22-2011 03:27 AM
[SOLVED] Extract multiple lines of data from a text file. shawnamiller Programming 8 04-30-2010 11:46 AM
extract substring using sed and regular expressions (regexp) lindylex Programming 20 12-22-2009 10:41 AM
Extract lines NOT on a block of text from a file Renan_S2 Programming 3 10-05-2008 04:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:23 PM.

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