to replace one character by numbers in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to replace one character by numbers in a file
# 1  
Old 10-05-2007
Java to replace one character by numbers in a file

suppose u have a file

aas P-H 123
gdg O-U 223
hdy I-Y 12
fgd K-O 333
ssa L-P 32

output shud be like that
aas P123H
gdg O223U
hdy I12Y
fgd K333O
ssa L32P

thanks
# 2  
Old 10-05-2007
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/p" input.txt


Last edited by vino; 10-05-2007 at 11:06 AM.. Reason: typo
# 3  
Old 10-05-2007
Quote:
Originally Posted by vino
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/g" input.txt

But if u have 0-9 digits then
\1\2\3 can we place [0-9]????
# 4  
Old 10-05-2007
Code:
 # awk '{sub("-",$3,$2);$3=""}1' "file"
aas P123H
gdg O223U
hdy I12Y
fgd K333O
ssa L32P

# 5  
Old 10-05-2007
not working......

Quote:
Originally Posted by vino
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/g" input.txt

sorry not working......
Regards
# 6  
Old 10-05-2007
Quote:
Originally Posted by cdfd123
sorry not working......
Regards
so are we expected to guess what's wrong? show your error messages..
# 7  
Old 10-05-2007
Quote:
Originally Posted by cdfd123
But if u have 0-9 digits then
\1\2\3 can we place [0-9]????
\1, \2, \3 so on and so forth are placeholders for the sub-regex expressions matched within each \( \) construct of a "s/regex/replacement/g" sed statement.

The sed statement should be
Code:
sed -n -e "s/\(.*\)-\([^ ]* \)\(.*\)/\1\3\2/p" input.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use awk to replace numbers in a file with a column from another file

Hello, I am trying to make a awk code that will take 2 files, a txt file like this : 1 1 88 c(1:38, 42, 102) 2 2 128 c(39:41, 43:101, 103:105, 153, 155:189, 292, 344:369) 3 3 84 c(190:249, 603, 606:607, 609:629) 4 4 12 ... (8 Replies)
Discussion started by: nastaziales
8 Replies

2. Shell Programming and Scripting

Replace character in a file.

I have a data like this in a file. 05/08/2017,U,01,116326001 05/08/2017,U,01,116226001 05/08/2017,U,01,116726323 05/08/2017,U,01,116236001 I want replace the date(1st column) of all records. Ex: 05/08/2017 to 04/02/2017 Please use CODE tags when displaying sample input, sample output,... (1 Reply)
Discussion started by: Artlk
1 Replies

3. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

4. Shell Programming and Scripting

Replace a character in a file

Hello, Can anyone help me? I need to replace the letters (A, B, C..) of the second column in this file by a number i.e. 1. current file 0123456 0A123 0003355 Marion 1234567 0B117 0003388 Anthony 1112333 0C345 0459877 Ann new file 0123456 01123 0003355 Marion 1234567 ... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

5. Shell Programming and Scripting

find all numbers > x and replace with y within a file

How would I do this? How could i use <> symbols for numbers in the find/replace code below? perl -pi -e 's/test/tst/' OR is there a better way? 100 5000 2 432 4 2 33 4 5 6 65 300 301 needs to be: 100 300 2 300 4 2 33 4 5 6 65 300 300 also it might not always need spaces... i... (12 Replies)
Discussion started by: herot
12 Replies

6. Shell Programming and Scripting

count numbers of matching rows and replace its value in another file

Hello all, can you help me in this problem, assume We have two txt file (file_1 and file_3) one is file_1 contains the data: a 0 b 1 c 3 a 7 b 4 c 5 b 8 d 6 . . . . and I need to count the lines with the matching data (a,b,..) and print in new file called file_2 such as the... (4 Replies)
Discussion started by: GoldenFalcon10
4 Replies

7. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

8. Shell Programming and Scripting

How to replace a character in the file?

Hi All, I have file contains the following information. chem00s4.mis.amat.com ] Critical 3/21 chem00s4.mis.amat.com ] Normal 3/22 chem00s4.mis.amat.com ] Normal 3/23 chem00s4.mis.amat.com ] Normal 3/24 chem00s4.mis.amat.com ] Critical 3/25... (2 Replies)
Discussion started by: ntgobinath
2 Replies

9. AIX

How to replace many numbers with one number in a file

How to replace many numbers with one number in a file. Many numbers like 444565,454678,443298,etc. i want to replace these with one number (300).Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies

10. Shell Programming and Scripting

How to replace a character in a file

Hi, I want to replace a character in every line in the file say the file looks like this SOBO20060830094122140014541834 WENP0414541835 ] SOBO20060830094121140014541834 WENP0414541835 SOBO20060830094121140014541834 WENP0414541835 I want to replace the blue 00 by TS. (6 Replies)
Discussion started by: preethgideon
6 Replies
Login or Register to Ask a Question