Top Forums UNIX for Beginners Questions & Answers Substitute a character with sed Post 303032263 by stomp on Thursday 14th of March 2019 09:44:02 AM
Hi bakunin,

thanks for the remarks about different aspects of sed -i.

Originally Posted by bakunin
So, if you rely on the file ownership or the filemode staying constant but have a directory with sticky bits set or if you rely that the inode number stays constant you are going to be disappointed.
Current GNU sed reapplies permissions and ownership after in-place edit. (Inodenumber is changed of course). I was not aware of that until know. Thanks for the hint. Grateful to the GNU-Developers, that they did a good job - here too.

See here(example as root user, so ownership-reapply is demonstrated):

# sed --version
# sed (GNU sed) 4.4

# ls -l test
-r--r--r-- 1 www-data www-data 5 Mär 14 14:16 test

# strace -o strace.out sed -r -i  's/bla/blub/' test

# ls -l test
-r--r--r-- 1 www-data www-data 5 Mär 14 14:17 test

# relevant parts within strace.out
# grep -E "(chmod|chown)" strace.out 
fchown(4, 33, 33)                       = 0
fchmod(4, 0100444)                      = 0

As a last concern i'd like to offer: it is not portable.
Yes, that's true. And as far as I understand, you are working in a more "pure" Unix-Environment (AIX, Solaris, ...) where this is very important to have scripts running on different platforms. And I assume scripts written will run on different platforms very often.

For my part I heavily rely on the GNU-Tools and what affects me, I'm working nearly 100% in a Linux environment(with different distributions) where the gnu collection is the default toolset in all cases. I think compatibility of my many scripts will break in lots of places because there are lots of differences in tools, different commands, same commands/different switches, ... . I think I would have a lot of extra work if I - for one thing - refrain from using the advanced feature set of the gnu tools and - for the other - to care about compatibility with systems I probably will never get in touch with.

Different worlds - Different rules ?

Last edited by stomp; 03-14-2019 at 01:01 PM..
These 2 Users Gave Thanks to stomp For This Post:
Test Your Knowledge in Computers #178
Difficulty: Medium
The Apple Computer Company was founded on April 1, 1978.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed substitute situation

I am having a problem executing a sed substitute in a file. I have tried alot of different things I found in previous posts, however non seem to work. I want to substitute this in $FILE: VALUE=33.4 In the script I have tried the following: prev=$(awk -F"=" '{ print $2 }' $FILE ) new=$(echo... (16 Replies)
Discussion started by: newbreed1
16 Replies

2. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies

3. Shell Programming and Scripting

Using SED to substitute between two patterns.

Hi All, I'm currently using SED to make various changes to some .xml files I'm working on, but I'm stuck on this particular problem. I want to remove '<placeholder>element-name</placeholder>' from the following: <heading>Element <placeholder>element-name</placeholder> not... (2 Replies)
Discussion started by: Steve_altius
2 Replies

4. AIX

check for a particular character inside a file and substitute with a given character?

i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character. consider a file test.txt,inside the file... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

5. Shell Programming and Scripting

Using sed to substitute first occurrence

I am trying to get rid of some ending tags but I run into some problems. Ex. How are you?</EndTag><Begin>It is fine.</Begin><New> Just about I am trying to get rid of the ending tags, starts with </ and ending with >. (which is </EndTag> and </Begin>) I tried the following sed... (2 Replies)
Discussion started by: quixoticking11
2 Replies

6. UNIX for Dummies Questions & Answers

Using sed to substitute between quotes.

I'm using sed to perform a simply search and replace. The typical data is: <fig><image href="Graphics/BAV.gif" align="left" placement="break" I need to replace the value in the first set of quotes, keeping the remainder of the line the same. Thus: <fig><image href="NEW_VALUE" align="left"... (3 Replies)
Discussion started by: Steve_altius
3 Replies

7. Shell Programming and Scripting

Sed question to substitute data in \2

Hi All, Here is what I'm trying to do with sed: Input File: somechangeVariable1=Something I would like to change somechangeVariable2=Something else I would like to change ... Output File: somechangeVariable1=Something I would like to different somechangeVariable2=Something else I would... (6 Replies)
Discussion started by: Peace_Dude1
6 Replies

8. Shell Programming and Scripting

How to substitute variable in sed for special character?

Hi , I have input file like below Hi this is "vinoth". Hi happy to work with 'unix' USA(united states of America) My script variables are below : Dquote=Ộ Squote=&#$567 Obrac=&^986 Cbrac=&^745 I want to read the variables in my SED command to replace the double quote,single... (9 Replies)
Discussion started by: vinothsekark
9 Replies

9. Shell Programming and Scripting

sed substitute command -- need help

I am trying to do what I thought should be a simple substitution, but I can't get it to work. File: Desire output: I thought I'd start with a sed command to remove the part of the header line preceding the string "comp", then go on to remove the suffix of the target string (e.g. ":3-509(-)"),... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

10. Shell Programming and Scripting

[sed]: Substitute a string with a multiline value

Dear all, I try to replace a string of characters in a file (MyFile.txt) by a multiline value of the variable "Myvar": $ cat MyFile.txt DESCRIPTION '@TargetTable SCHEMA' ( @InputFlowDef ); $ The content of Myvar: $ echo "$Myvar" col1 , col2 , col3 $ (4 Replies)
Discussion started by: dae
4 Replies

Featured Tech Videos

All times are GMT -4. The time now is 05:56 PM.
Unix & Linux Forums Content Copyright 1993-2019. All Rights Reserved.
Privacy Policy