LinuxQuestions.org
Help answer threads with 0 replies.
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 10-17-2003, 06:07 PM   #1
mark2117
LQ Newbie
 
Registered: Sep 2003
Posts: 12

Rep: Reputation: 0
Vi with a sed filter


Hey Everyone,

I was editing an old script and need to do some repetative changes with numbers. I wanted to reduce a group of numbers (40-50) for simpilicities sake let say ten an many lines thoughout the script. I ended up doing:

:%s/40/30g

This worked fine on number at a time. However I am could never figure out why this wouldn't work:

:1,$!sed "s/[4-5][0-9]/`echo \& -10|bc`/g

The echo worked fine, but when I added the "bc" it killed it. Any other suggestions for the future???

I know I could have did it in perl, or an shell script...but I really just wanted to do it in Vi and it seems to me there must be a way Maybe sed was the wrong choice???

BTW, I don't think it makes to much of a diff this particular one I was doing on HP-UX 11.

Thanks,
Mark
 
Old 10-18-2003, 04:46 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
"& -10" is not a valid command for bc
Code:
heiko@hko:~/dummy$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
& -10
(standard_in) 1: illegal character: &
 
Old 10-20-2003, 03:56 PM   #3
mark2117
LQ Newbie
 
Registered: Sep 2003
Posts: 12

Original Poster
Rep: Reputation: 0
Correct, however "\&" holds the matched item in a regex. If you run without the "|bc" you would see the resultant would show something like "40-10" thats what should get piped to bc.....right???

Mark

Last edited by mark2117; 10-20-2003 at 04:00 PM.
 
  


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
Spam filter to external mail filter deadlock Linux - Software 1 06-16-2004 02:28 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
filter martini1050 Linux - General 0 03-01-2004 02:07 PM
L7 Filter Xing Linux - Software 0 09-17-2003 04:56 AM

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

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