substitute a line in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting substitute a line in file
# 1  
Old 09-24-2008
substitute a line in file

i have an file ,i want to substitute line
003 M 33 22 22 00
WITH NEW
003 M 24 26 28 00
how can i do it
# 2  
Old 09-24-2008
Hammer & Screwdriver Doing it with sed

Code:
> cat file2
003 M 33 22 22 00
004 M 33 22 22 00
005 M 33 22 22 00
006 M 33 22 22 00
> cat file2 | sed "s/003 M 33 22 22 00/003 M 24 26 28 00/g" >file3
> cat file3
003 M 24 26 28 00
004 M 33 22 22 00
005 M 33 22 22 00
006 M 33 22 22 00

Or, without the 'cat' command to get same result:-)
Code:
> sed "s/003 M 33 22 22 00/003 M 24 26 28 00/g" <file2 >file4
> cat file4
003 M 24 26 28 00
004 M 33 22 22 00
005 M 33 22 22 00
006 M 33 22 22 00

# 3  
Old 09-24-2008
thanks its working ,but can u please tell me why you use " " instead of ' '
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Substitute particular char in a file

I have a file like this. 1 aaa bcd 1 56 xyz 1 2 ccc rrr 1 25 512 1 1 zaz eee 1 55 511 1 I want to change middle 1's ie after bcd,rrr,eee to 0 where as other 1's should not change. Can you please provide a solution . (5 Replies)
Discussion started by: kshari8888
5 Replies

2. Shell Programming and Scripting

Substitute one line of multiple files according to another file

I need to make ~96 configure files from a template config file which has hundreds of rows that looks like: template.config: #average insert size avg_ins=1000 ...... other information omitted Those config files are named in sequence from S01.config, S02.config, ... etc with different... (11 Replies)
Discussion started by: yifangt
11 Replies

3. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

4. UNIX for Dummies Questions & Answers

Help with AWK - Compare a field in a file to lookup file and substitute if only a match

I have the below 2 files: 1) Third field from file1.txt should be compared to the first field of lookup.txt. 2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt. 3)Else just print the line from file1.txt. File1.txt:... (4 Replies)
Discussion started by: venalla_shine
4 Replies

5. Shell Programming and Scripting

substitute a line in a file if line number is available

Hi guys, is there are way to substitute the content of certain line in the file by another entry if line number is available? For example, I have a variable A="HCMLPBBG" and a file MYFILE. I need to substitute entry on line 18168 of MYFILE with the value of the variable "A". Is there a way to... (1 Reply)
Discussion started by: aoussenko
1 Replies

6. Shell Programming and Scripting

How to substitute a line that matches an expression with another line

I need some help. I have a file (all.txt) whereby I want to substitute using sed/awk all lines that matches an expression with another line with different expression i.e subtitute expression, database_id: filename; WITH database_id: PY; There are many occurrences of the expression... (4 Replies)
Discussion started by: aimsoft
4 Replies

7. Shell Programming and Scripting

How to substitute in a large gz file?

I have a large .gz file where i wish to replace the occurrence of a particular word with another word.. Can anyone help?I prefer a short script.. Can sed work with gz files? (5 Replies)
Discussion started by: maximus8886
5 Replies

8. UNIX for Dummies Questions & Answers

substitute file name

correct file names are: *_0.txt *_1.txt incorrect file names are: *_12.txt *_0123.txt *_04321.txt all files that are incorrect need to replace the ending with *_1.txt therefore need to create a loop to find the wrong files in a dir ->that dont end in _1.txt or _0.txt and then... (3 Replies)
Discussion started by: sigh2010
3 Replies

9. Shell Programming and Scripting

Substitute File name

Hi all I am in a small problem pl help me out. I am having a directory having ZIP files with name starting as : 01.xyz 02.pqr and so on I want to run the script- cat myfile | awk '{print $1, $2}' | while read var1 var2 do zcat $var2* | grep "^000$var1" >> my_output done Where the... (22 Replies)
Discussion started by: vanand420
22 Replies

10. Shell Programming and Scripting

substitute string according line number

Hi all, I have an xml file which have several sections as the following: <process-type id="NIR" module-id="OC4J"> <module-data> <category id="start-parameters"> <data id="java-options" value="-server... (4 Replies)
Discussion started by: nir_s
4 Replies
Login or Register to Ask a Question