sed : Making changes in the same file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed : Making changes in the same file
# 1  
Old 07-17-2002
sed : Making changes in the same file

sed 's/abc/xyz/g' abc.txt > abc.txt

This change all the abc s in abc.txt to xyz s but does not write back to the abc.txt.

Suggest me the cleaner way without using temp file please.

Cheers,
Amol.
# 2  
Old 07-17-2002
Hi,

IMHO there´s no way to work without any tmp files, cause if you redirect the STDOUT to abc.txt the (empty) file is created before sed can read it. So sed is reading an empty file!

but what is the problem working with a tmp file?

I tried out this an it works fine.

sed 's/abc/xyz/g' abc.txt>xyz.txt;mv xyz.txt abc.txt


Hope this meets your affords.

greetz,
Frank
# 3  
Old 07-17-2002
I'm afraid isacs is right there..... sed cannot be directed back to it's file....it's just the way it was written.

There are some Unix commands that can.....'sort' for example can have a -o flag set to be the input filename. But sed cannot - there is no cleaner way using sed.
# 4  
Old 07-17-2002
Ahh, I wonder what would be the reason, this is not provided in sed implementation, maybe they did not want to keep enitre file in memory, this is good when reading bigg files....anyways, I will use the temp files.

temp files is problem coz I am doing this with lots of other files at the same time throught different threads..and although I can create unique temp files, the problem is I would need large free space to creat them as maybe 100s of temp files will be created simultaniously. Hmmm I need to think on this....well....thanks people !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Making SED case insensitive

Dears, In the below string, please let me know how to make the sed search case-incensitive. I have more such lines in my script instead of let me know any other easier option. sed -n '/dn: MSISDN=/,/^\s*$/p' full.ldif > temp ; sed -n... (4 Replies)
Discussion started by: Kamesh G
4 Replies

2. Shell Programming and Scripting

making find/sed to include directory names with spaces

how can i make find/sed to include directory names with spaces the command is like this for i in `find wp-content/themes -type f -print0 | xargs -0 grep -l -iE 'e'`;do sed -i -e 's/word1/word2/gI' "$i";done but it skips one directory names with spaces sed: can't read ./Nova: No such... (5 Replies)
Discussion started by: vanessafan99
5 Replies

3. Shell Programming and Scripting

making sed command case insensitive

i have something like this in a file cat onlytables.sql create table NextID ( id int auto_increment, zoneID int, entityName varchar(64), nextID int, lastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary... (6 Replies)
Discussion started by: vivek d r
6 Replies

4. Shell Programming and Scripting

making the first character of word using uppercase using awk and sed

I want to make the first character of some words to be uppercase. I have a file like the one below. uid,givenname,sn,cn,mail,telephonenumber mattj,matt,johnson,matt johnson,mattj@gmail.com markv,mark,vennet,matt s vennet,markv@gmail.com mikea,mike,austi,mike austin,mike@gmail.com I want... (3 Replies)
Discussion started by: matt12
3 Replies

5. Shell Programming and Scripting

Making use of multiple cores for running sed and awk scripts

Hi All, After reading that the sort command in Linux can be made to use many processor cores just by using a simple script which I found on the internet, I was wondering if I can use similar techniques for programs like the awk and sed? #!/bin/bash # Usage: psort filename <chunksize>... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

6. UNIX for Dummies Questions & Answers

Making replicates of a file with part of a line randomized for each file

Ok, so let's say that I have a file like the following: I want to create 100 replicates of this file, except that for each file, I want different randomized combinations of either A or B at the end of each line so that I would end up with files like the following: and etc. I... (1 Reply)
Discussion started by: Scatterbrain26
1 Replies

7. Shell Programming and Scripting

non alpha characters in sed + making it fast?

hello, I'm trying to write the fastest sed command possible (large files will be processed) to replace RICH with NICK in a file which looks like this (below) if the occurance of RICH is uppercase, replace with uppercase if it's lowercase, replace with lowercase SOMTHING_RICH_SOMTHING <- replace... (10 Replies)
Discussion started by: rich@ardz
10 Replies

8. Shell Programming and Scripting

Making substring with sed

Input: You can easily do this by highlighting your code. How can i get the substring from index 9 to 12 using sed? (6 Replies)
Discussion started by: cola
6 Replies

9. Shell Programming and Scripting

SED is making my head-hurt...

Hi all! Shell-scripting n00bie here... I'm having a terrible time getting my head around how to use the sed command & could really use some help. Basically, I'm trying to use sed to remove all characters of a line up to a '<' character within a text-file. It would be spectacular if there... (2 Replies)
Discussion started by: mxedit10n
2 Replies

10. Shell Programming and Scripting

Making Changes without opening file

Hello, I'm new to scripting, I have a file test.dat. I want to make changes to it with out openning it. Example: test.dat has rows, and I want to change value "LA" to "TX" without opening it or without writing it to another file. Is it possible? Thanks (9 Replies)
Discussion started by: irehman
9 Replies
Login or Register to Ask a Question