Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Substitute a character with sed Post 303032286 by MadeInGermany on Thursday 14th of March 2019 06:10:18 PM
Old 03-14-2019
Bakunin's replacement code in post#4 is portable but still creates a new inode for the input file ("/path/to/file")
This not only denotes a repair of the original owner/group/permissions, it will make a previously hard-linked file stand-alone, and this damage cannot be repaired.
Also GNU sed -i (and perl -i) cannot preserve the original linkage.
If we are going for a real improvement then we avoid the mv command!
Code:
if sed '....' /path/to/file > /path/to/file.tmp ; then
     cp  /path/to/file.tmp  /path/to/file
else
     <error handling procedure here>
fi

The cp command preserves the original inode (owner/group/permissions and linkage) - only the timestamp changes, and that's pretty correct.
This User Gave Thanks to MadeInGermany For This Post:
 

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

using sed or gsub to substitute characters!

Is there a way to substitute the URL-encoding references of ( & and ` ) with their actual appearance? for example.... %26 is & say I want to convert every %26 in my file to &..... awk '{gsub(/%26/,"&");print}' Is there a way to do this? I also want to be able to convert ` too! (3 Replies)
Discussion started by: puttster
3 Replies

9. 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

10. 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
diskowner(1M)															     diskowner(1M)

NAME
diskowner - retrieve the owner of a storage device SYNOPSIS
path DESCRIPTION
The command is used to retrieve the subsystem, if any, which is using the specified path. The command is intended to help prevent users from overwriting storage that is already in use. The command will print out the owner of the path, or if no owner was found. A storage device is considered owned by a subsystem if it has been formatted by that subsystem. For example, if a disk contains a VxFS filesystem, but is not mounted or in use, it is still considered owned by the VxFS subsystem. If the path specified is invalid or inaccessible, an error message will be printed. Options and Arguments The command recognizes the following options and arguments: path The path name to the storage device. The path may be a symbolic link, as long as it points to a storage device, such as a file, disk, or logical volume. List all the owners of the specified path, seperated by commas Produce a compact output that is easily parsed by other scripts and programs. When used with option, displays all the owners seperated by dots This format is described in the section below. Output from diskowner displays the following possible output: owner The owner of the given path. owner can be one of the following: The path is not owned by any known subsystem. The path is part of an LVM volume group. The path is part of a VxVM volume group. The path has a VxFS filesystem on it. The path has a HFS filesystem on it. The path is being used as a swap device. The path is being used as a dump device. The path is part of an Oracle database. The path has EFI partitions on it. message An error message displayed when the given path is invalid or inaccessible. Compact Listing The option generates a compact, colon delimited listing that is easy to parse. The output format is: and so forth. The option, when used with the option, produces this output format: and so forth. The current command prints out the keys and values listed below. In the future, new keys and/or values may be added to the output. or or where path is the pathname passed as argument owner is the owner of the given path message is an error message when given path is invalid or inaccessible. n is number of owners of the given path EXTERNAL INFLUENCES
Environment Variables determines the language in which messages are displayed. If is not specified or is null, it defaults to "C" (see lang(5)). If any internationalization variable contains an invalid setting, all internationalization variables default to "C" (see environ(5)). RETURN VALUE
Upon completion, returns one of the following values: The path is not owned (the owner is The path is already owned by a subsystem. The path does not exist. Invalid options or library version incompatible. The path cannot be opened due to an I/O error. The path cannot be opened due to insufficient permissions. The path format is invalid. EXAMPLES
Display the owner of a disk path: Display the owner of a logical volume in compact output: Display all the owners of a disk path: Display all the owners of a logical volume in compact output: SEE ALSO
crashconf(1M), df(1M), swapinfo(1M), vgdisplay(1M), vxvmboot(1M), vxassist(1M), fstab(4). diskowner(1M)
All times are GMT -4. The time now is 09:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy