General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 24th, 2012, 12:14 PM
scary3@uncc.edu scary3@uncc.edu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 scary3@uncc.edu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 20 sec
Reputation Power: 0
Putting variables in the sed command in vim

I've just started using Linux and vim, and I'm pretty new to programming in general. I'm trying to write a program in vim that writes certain lines of one file to another file, and I'm trying to use a while loop and the sed command. It looks like this:

#bin/bash
sed -n '10w file2' file1
x=11
while [ $x -lt 100 ]; do
sed -n '$xw file2' file1
x=$((x + 44))
done

When I run the program it gives me this message:

sed: -e expression #1, char 3: extra characters after command
sed: -e expression #1, char 3: extra characters after command
sed: -e expression #1, char 3: extra characters after command

I tried putting the variable in double quotes, "$x" but that did not work. How can I make the sed command recognize that it is a variable?

Reply With Quote
  #2  
Old May 24th, 2012, 12:37 PM
scary3@uncc.edu scary3@uncc.edu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 scary3@uncc.edu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 20 sec
Reputation Power: 0
Also, I know how to use the yank (yy) and paste (p) commands, as well as the write to file comand, :<m>, <n> w newfile. The problem is that I am dealing with a programs that have over 85000 lines, and there are 88 of these in total. If there is a better method than the one I am trying to use, some guidance would be really helpful.

Reply With Quote
  #3  
Old May 25th, 2012, 12:54 PM
scary3@uncc.edu scary3@uncc.edu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 scary3@uncc.edu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 20 sec
Reputation Power: 0
Sorry, I guess this was a dumb question. Single quotes seemed to do the trick. Anyway, I found that the grep command was more efficient for what I wanted to do, if anyone is looking to do something similar in the future. Thanks to anyone who might have been looking into it for me.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Putting variables in the sed command in vim


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap