Sponsored Content
Top Forums Shell Programming and Scripting sed substitue whole file + 1 substitue with variables on one sed line?. Post 302987065 by itman73 on Sunday 4th of December 2016 11:43:32 AM
Old 12-04-2016
sed substitue whole file + 1 substitue with variables on one sed line?.

I'm trying to remove '--X' from the whole file and using variables replace $oldvar with $newvar.

I have tried with double quotes but it doesn't seem to work. $newvar is set to /usr/bin/bash. Would appreciate some guidance.

Code:
newvar=$(which bash)
oldvar=/bin/bash
  
sed "s/^--X//;1s#!$oldvar#!$newvar#" <infile >outfile

Input is:
Code:
echo $newvar
$ /usr/bin/bash

cat infile
--X#!/bin/bash

Result is:
Code:
#!/bin/bash

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help for VNS substitue solution.....

Hello Unix Gurus, We are doing large system upgrade. We expect upgrade to last 180-200 hours. The servers are located remotely. I am looking for solution which allows me to reconnect to the same session active on unix server where I launched the process. This would protect from local client... (0 Replies)
Discussion started by: mehtasa
0 Replies

2. Shell Programming and Scripting

Need to substitue space with \n

I have a file with a single line in it as below. field1 field2 field3 Different fields separated by spaces. I need the output as below. field1 field2 field3 Any sed/awk solution you can suggest? (6 Replies)
Discussion started by: krishmaths
6 Replies

3. Shell Programming and Scripting

substitue of values.

$db2 connection ...........Q a=`$db2 -x "select A from tablename where z in (select z from tablename Q where condition fetch first 1 rows only ) with ur"` b=`$db2 -x "select B from tablename where z in (select z from tablename Q where condition fetch first 1 rows only) with ur"` $db2... (2 Replies)
Discussion started by: rollthecoin
2 Replies

4. Shell Programming and Scripting

Can i use Variables in sed command in line numbers

I wish to give line number from one point to another in sed command like this sed -n 1,1000000p file1.txt >file2.txt but variable line number $x,$x+100000 can i give it cos i tried and it was giving an error any suggestions?/ Thx in advance AC (2 Replies)
Discussion started by: bezudar
2 Replies

5. Shell Programming and Scripting

sed command - substitue first instance

hi i have one file where i want to substitute only first instance of swap with swap1 i want to replcae only first instance of swap in my script i know we can do this with awk. but i need to do this with sed only i tried follwoing code sed 's/swap/swap1' filename but here all... (15 Replies)
Discussion started by: d_swapneel14
15 Replies

6. UNIX for Dummies Questions & Answers

Substitue 'Special Characters' in VI

Hi All, I am using LATEX and need to delete all the lines in a file matching: \begin{work} I know there are several ways to do this, but I am trying to do it with the substitute command in VI. The problem is I can't get substitute to recognize the character '\'! How do I do it? ... (7 Replies)
Discussion started by: ScKaSx
7 Replies

7. AIX

insert a line with variables using sed

Hi, I have to insert a line having variables using sed. But the variables are not getting substituted within sed. Ex: n=2 sed $n' i\ hi' file This works. But the below code does not work. n=2 line=hello sed $n' i\ $line' file The above code inserts '$line' in the 2nd line of the... (9 Replies)
Discussion started by: sugan
9 Replies

8. Homework & Coursework Questions

Bash Scripting - sed (substitue)

1. The problem statement, all variables and given/known data: I have been asked to create a bash script to delete comments from another file but in the file they have an echo command with this inside of it /* this is an echo */\ so obviously they want to keep this one in the file. I have found... (5 Replies)
Discussion started by: syco__
5 Replies

9. Shell Programming and Scripting

using sed command to display contents where line numbers are stored in variables

if i want to display the contents of a file between say line number 3 and 10 then i use the following command sed -n '3,10p' filename if this 3 was contained in x and 10 was contained in y then how wud this command modified? sed -n '$x,$yp' filename does not work..please advise (2 Replies)
Discussion started by: arindamlive
2 Replies

10. Shell Programming and Scripting

Sed, replace variables in file

Hi Everyone, I need some help with sed and I'm totally new to it. I have a template file with variables in it. These variables start with a '$' sign and are exactly one character long (plus the '$' sign). For example: $a, $b, etc. Each variable should be replaced with the contents of a... (9 Replies)
Discussion started by: csarli2006
9 Replies
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh. Note that /etc/shells overrides the default list. Invalid shells in /etc/shells may cause unexpected behavior (such as being unable to log in by way of ftp(1)). FILES
/etc/shells lists shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.10 4 Jun 2001 shells(4)
All times are GMT -4. The time now is 06:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy