replacing a string with another string in a txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replacing a string with another string in a txt file
# 8  
Old 03-18-2011
Thnaks a lot! it really helpful!!
# 9  
Old 03-18-2011
Quote:
Originally Posted by forevertl
thanks! One more question: if I want only replace the dot in a certain column, saying 3rd column, how to do that? sorry, I am new to unix. Thanks again!
If your 3rd column is the last column (so if your file is made of 3 columns, then this will also works :
Code:
# cat tst
8 70003200 21.6206
9 70005700 17.5064
10 70002200 .
11 70005100 19.1001
17 70008000 16.1970
32 70012400 26.3465
33 70014900 19.2607
34 70015500 19.1406
35 70007800 18.0802
36 70015300 .
37 70008600 16.1844

Code:
# sed 's/\.$/NA/' tst
8 70003200 21.6206
9 70005700 17.5064
10 70002200 NA
11 70005100 19.1001
17 70008000 16.1970
32 70012400 26.3465
33 70014900 19.2607
34 70015500 19.1406
35 70007800 18.0802
36 70015300 NA
37 70008600 16.1844
#

Code:
# cat tst
8 70003200 21.6206
9 . 17.5064
10 700.02200 .
11 . .
17 70008000 16.1970
32 70012400 26.3465
33 70014900 19.2607
34 70015500 19.1406
35 70007800 18.0802
36 70015300 .
37 70008600 16.1844
# sed 's/\.$/NA/' tst
8 70003200 21.6206
9 . 17.5064
10 700.02200 NA
11 . NA
17 70008000 16.1970
32 70012400 26.3465
33 70014900 19.2607
34 70015500 19.1406
35 70007800 18.0802
36 70015300 NA
37 70008600 16.1844


Last edited by ctsgnb; 03-18-2011 at 03:58 PM..
# 10  
Old 03-18-2011
Thanks! I learn a lot today!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replacing a particular string in all files in folder and file contents

I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, AK6-system.py etc.. the files names as well as contents should be changes to AK9-Create.xml, AK9-system.py etc All files are xml and python scripts. ---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies

2. Shell Programming and Scripting

Replacing string values from a File

I want to replace string values from a file to a file For eg : File1 has 30 lines of string with values, those specific values needs to be changed in file2 and remaining values in file2 should be as it is. For example: From file (File1) cluster.name=secondaryCluster To replace File... (9 Replies)
Discussion started by: sriram003
9 Replies

3. Programming

Need help for replacing a string in a text file at runtime !

Hi All, I am facing an issue... I need to replace some string in a text file while the same file is read by some other user at the same time. The other user is using it in the Read only mode. So I can't create a temporary file and write the content first and then write it back into the original... (2 Replies)
Discussion started by: agupta2
2 Replies

4. Shell Programming and Scripting

replacing a string in multiple subdirs to a new string??

I have following set of dirs: /dir1/dir2/subdir1 file1 file2 /dir1/dir3/subdir1 file4 file5 /dir1/dir4/subdir1 file6 file7 All of these files have a common string in them say "STRING1", How can I... (3 Replies)
Discussion started by: Hangman2
3 Replies

5. UNIX for Advanced & Expert Users

Convert delimiter to string in txt file

Hi, I need to convert tab delimiter to #*# in txt file. Does anybody know how to do it? If i'm using: tr -s '\t' '#*#' < name.txt > name_new.txt It converts only to #, but I need 3 chars. Thanks a lot. (2 Replies)
Discussion started by: borsud
2 Replies

6. Shell Programming and Scripting

Replacing a character string in a file

Hi there, I have a paramater file that looks like this :- IRL|07122005|27389|VTIEpay|email address|5|200 When my program finishes I want to replace the seventh field. the existing code is like this cat <<-EOF | ed -s $PARFILE 1,$ g/^$ICO/s/$prvdate/$TODAY/ 1,$... (13 Replies)
Discussion started by: rjsha1
13 Replies

7. Shell Programming and Scripting

replacing string in an XML file

Hi all, I need to replace string in XML file..XML file like <dependency> <groupId>fr.orange.portail.ear</groupId> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <type>ear</type> </dependency> <dependency> ... (2 Replies)
Discussion started by: subin_bala
2 Replies

8. Shell Programming and Scripting

replacing a string in a file with command line parameter

Hello, I am trying to replace a string with a paramter given along with the script. I am replacing application1 to application2 with the script: ./change_app.sh application2 change_app.sh: #!/bin/ksh grep $1 applications.dat 2>&1 >/dev/null echo $1 file=pckage.new sed 's/Name:... (5 Replies)
Discussion started by: chiru_h
5 Replies

9. UNIX for Dummies Questions & Answers

How to redirect date with string command into txt file

Hello im trying to redirect the standard output into txt file but with combination of string if I do : date >! foo.txt there is no problem and im getting the date into the foo.txt but what should I do if I like to add string in the same command so the result will be in the txt : The date... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question