Sponsored Content
Top Forums Shell Programming and Scripting How to paste lines below certain text (Script) Post 302592012 by xxxx on Sunday 22nd of January 2012 11:30:16 AM
Old 01-22-2012
Quote:
Originally Posted by Franklin52
If your sed version supports the -i (in place) option:
Code:
sed -i 's!SCGIMount /RPC3 127.0.0.1:5001!SCGIMount /RPC3 127.0.0.1:5000!' apache2.conf

Otherwise:
Code:
sed 's!SCGIMount /RPC3 127.0.0.1:5001!SCGIMount /RPC3 127.0.0.1:5000!' apache2.conf > tempfile
mv tempfile apache2.conf


Thank you. This works in the terminal perfectly. However, it doesn't seem to work in a bash script. Been messing around with all sorts of way for hours now.

An example :

Code:
#!/bin/bash
# Script to add a startup item

username=somethingrandom

cp /etc/init.d/originalfile /etc/init.d/$username
sed 's!changeusername!$username!' /etc/init.d/$username > tempfile
mv tempfile /etc/init.d/$username
chown root:root /etc/init.d/$username
chmod 777 /etc/init.d/$username

I've renamed the file in the script to changeusername so its easier. However it doesn't work with the string $username present. If i were to replace $username with "somethingrandomhere" then it would work. However, i want it to change according to the username that i've given in the script.

(Script has been modified for the thread so it would be less complicated. In the real script, I would be asked to input the username)
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copy/Paste text as commands in AIX

Hello, I'm absolutely new to this world... but I've a problem with a terminal connected via PuTTY (or Termlite) to an AIX 5.1 application. The problem: I need to paste from clipboard a text containing both input text strings and special keys as ESC, Arrows and so on, to execute in the AIX... (1 Reply)
Discussion started by: Daniele11
1 Replies

2. UNIX for Dummies Questions & Answers

vi editor prefixes lines with # upon paste

I've been away from Unix and the vi editor for a while, and now I'm using vi (actually vim) in a Cygwin bash shell. When I copy-and-paste code examples (I'm playing with perl now) any time I paste code with lines beginning with the # character, vi inserts a # character at the beginning of every... (2 Replies)
Discussion started by: greenmangroup
2 Replies

3. Shell Programming and Scripting

Need helpl in scripting read 2 lines and paste to one single line.

Hi All, I need to create script which will accept one file as i/p and give me o/p file described as below. 1) i/p log file named abc.log contents several lines but i am interested in lines like below. #FILE..... /oracle/XYZ/sapdata1/undo_7/undo.data7 #SAVED.... BACKINTID001 2) o/p... (4 Replies)
Discussion started by: paragp1981
4 Replies

4. Shell Programming and Scripting

awk/grep copy and paste and insert in between lines.

Hi all, I'm a unix newb andI'm trying to write a script that can copy some text paste it in a certian place and then add a number. It's not really clear but I'll show an example. what the file looks like right now: Linux 2.6.24-24-generic (abc) 07/15/09 23:25:01 CPU ... (6 Replies)
Discussion started by: the1hand3r
6 Replies

5. UNIX for Dummies Questions & Answers

copy and paste certain many lines of huge file in linux

Dear All, I am working with windoes OS but remote a linux machine. I wonder the way to copy an paste some part of a huge file in linux machine. the contain of file like as follow: ... dump annealling all custom 10 anneal_*.dat id type x y z q timestep 0.02 run 200000 Memory... (2 Replies)
Discussion started by: ariesto
2 Replies

6. Solaris

Copy and paste text from a word document into a txt file in vi

Hello, Can anybody please tell me how we can copy and paste text from a word document into a text file that we are editing in vi? Is it possible to do that while we are editing the text file in vi in insert mode? Thanks, (3 Replies)
Discussion started by: Pouchie1
3 Replies

7. OS X (Apple)

Paste text into vi file?

Hello, I'm running OS X 10.7.4. How can I paste text from the pasteboard into an open vim file? Thanks! (21 Replies)
Discussion started by: palex
21 Replies

8. UNIX for Dummies Questions & Answers

Copy Lines between Keywords & paste them to another file

hi, I have Multiple files with the following data : File1 100414 DR1 END XXXXX Test1 Test2 Test3 Test4 Test5 Test6 END 100514 DR2 END XXXXX Test7 Test8 Test9 Test10 Test11 Test12 END 100614 DR3 (5 Replies)
Discussion started by: newageBATMAN
5 Replies

9. Shell Programming and Scripting

Copy and paste text inside a xml file

I have a really big XML file. I need copy the value of one tag inside another one tag. I try to publish one example. <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1">Rai 1</channel> <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1 +2HD">Rai 1... (6 Replies)
Discussion started by: Tapiocapioca
6 Replies

10. Shell Programming and Scripting

Bash copy and paste text in file from one position to another

Hi I have a text file with lines beginning with 71303, 71403, 71602, I need to copy the 10 digit text at position 30 on lines beginning with 71303 (5500011446) to position 99 on every line beginning with 71602 (see example below), There may be many 71303 lines but I need the text copying to... (2 Replies)
Discussion started by: firefox2k2
2 Replies
cancel(1)							    Apple Inc.								 cancel(1)

NAME
cancel - cancel jobs SYNOPSIS
cancel [ -E ] [ -U username ] [ -a ] [ -h hostname[:port] ] [ -u username ] [ id ] [ destination ] [ destination-id ] DESCRIPTION
cancel cancels existing print jobs. The -a option will remove all jobs from the specified destination. OPTIONS
The following options are recognized by cancel: -E Forces encryption when connecting to the server. -U username Specifies the username to use when connecting to the server. -a Cancel all jobs on the named destination, or all jobs on all destinations if none is provided. -h hostname[:port] Chooses an alternate server. -u username Cancels jobs owned by username. COMPATIBILITY
Unlike the System V printing system, CUPS allows printer names to contain any printable character except SPACE, TAB, "/", or "#". Also, printer and class names are not case-sensitive. NOTES
Administrators wishing to prevent unauthorized cancellation of jobs via the -u option should require authentication for Cancel-Jobs opera- tions in cupsd.conf(5). SEE ALSO
lp(1), lpmove(8), lpstat(1), http://localhost:631/help COPYRIGHT
Copyright 2007-2009 by Apple Inc. 20 March 2006 CUPS cancel(1)
All times are GMT -4. The time now is 01:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy