translate text (1 position) with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting translate text (1 position) with sed
# 1  
Old 12-11-2003
translate text (1 position) with sed

Hello,

I'm trying to translate a fixed length (the first 6 positions) that begins with a 0 to overwrite the field with an *.

Any suggestion?

File 1
-------

013344 01:20
222343 19:30
233333 20:30


File 2 (result)
-----------------

****** 01:20
222343 19:30
233333 20:30
# 2  
Old 12-11-2003
sed 's/^....../******/' file1 > file2
# 3  
Old 12-11-2003
Ygor's solution will change the first 6 positions of every line in the file. I think the OP only wants the the first 6 positions of line 1 changed. If so:

sed '1s/^....../******/' file1 > file2
# 4  
Old 12-11-2003
"that begins with a 0"

i guess it should be

sed 's/^0...../******/' file1 > file2
# 5  
Old 12-11-2003
If you want to match the field only that contains digits only, then:

sed 's/^0[0-9]\{5\} /****** /' file1 > file2

It matchs the field starting with 0 and 5 digits follow it. I added one more space in both of pattern and replacement for more accuracy.
# 6  
Old 12-12-2003
Thank you for the solutions, it works great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Usage of sed, position of apostrophe

Hello, I have never ever seen below notation for string substitution. sed -i -e 's/tttt/pppp'/g /var/bin/czech.sh; The strange thing for me is the position of the apostrophe. Should it be before the / or after the g? If I had been writing that command line, I would have chosen below way:... (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Change text at a variable position

Hi there script guru's I have an input file /tmp/in.txt of which the data is seperated by a : (example of the data) test1:zz:2000:2000:zzz te:a:2000:3333:bbb testabs:x:2004:3000:cccc I would like to run a scrip (bash) changing the data after the second ":" example Test for the value of... (3 Replies)
Discussion started by: KobusE
3 Replies

3. Shell Programming and Scripting

translate sed to awk

hi, can someone tell me how can I translate the following line from sed to awk? `sed 's/^*:*:*:*:*:\(*\):.*/\1/ How to use code tags when posting data and code samples. (14 Replies)
Discussion started by: adam25bc
14 Replies

4. Shell Programming and Scripting

Translate Text File w/ shell

Hello everyone! I'm having some problems trying to translate a text file. I've found some TR and SED commands but doesnt work exactly as I need. The point is: 1. Replace all the letters with accent of a text file, like this: Ã>A Á>A Õ>o 2. Replace all the special characters with a... (3 Replies)
Discussion started by: ulysses2703
3 Replies

5. Shell Programming and Scripting

Using sed to replace a string in a specific position

I asked this before, but my problem got more complicated. Heres what I am trying to do: I'm trying to replace a string at a certain location with another string. Heres the file I'm trying to change: \E I want to replace the escape code at the 3rd line, 2nd column with this escape code... (3 Replies)
Discussion started by: tinman47
3 Replies

6. Shell Programming and Scripting

Sed position specific replace

I'm drawing a blank on how to use sed to replace selectively based on position in the string (vs nth occurence): hello.|there.|how.|are.|you.| I want the period removed in the 3rd item (as defined by the pipe delimiter) if a period is present. So the result in this case would be: ... (2 Replies)
Discussion started by: tiggyboo
2 Replies

7. Shell Programming and Scripting

Remove text from n position to n position sed/awk

I want to remove text from nth position to nth position couple of times in same line my line is "hello is there anyone can help me with this question" I need like this ello is there anyone can help me with question 'h' is removed and 'this' removed from the line. I want to do this... (5 Replies)
Discussion started by: elamurugu
5 Replies

8. Shell Programming and Scripting

How to replace symbols by position using SED

Hi all, I need your help. For example I have string in file.txt: -x -a /tmp/dbarchive_NSS_20081204 -f 900 -l 1 2008/12/04 2008/12/04 So, I need to replace symbols from (for e.g.) position 26 till 33 with symbols which I have in file replace.txt And I have no idea how to do it. If... (1 Reply)
Discussion started by: nypreH
1 Replies

9. Shell Programming and Scripting

Relace text based on position

Hi, I have a file with data like below a}hasksd09090}kdkdkd aksdkdkdk787}08ksapodd asl}alks13233}dsjskdkd I need to replace any '}' to 0 if it appears in 10 to 15 postions.If } appears in any other postion I need to leave it. So for the above data , output should be a}hasksd090900kdkdkd... (1 Reply)
Discussion started by: dncs
1 Replies

10. Shell Programming and Scripting

Text replace by position instead of reg expr.

Can we replace the contents the of the rows of file, from one position to another position by mentioning, some start position & the width? (4 Replies)
Discussion started by: videsh77
4 Replies
Login or Register to Ask a Question