replace chars,


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace chars,
# 1  
Old 02-28-2007
replace chars,

Smilie Hi,

I want to replace the particular text in the middle of the line.
Ex. In the line 40-50 wanted to replace the char as 'x'
# 2  
Old 02-28-2007
If x="21312312dennis3123123123"
echo ${x/dennis/xxxxxx}
x will be 21312312xxxxxx3123123123 now

echo $x |sed 's/dennis/xxxxxx/' will also give the same result.

I hope this is what you are expecting!!
# 3  
Old 02-28-2007
something like this,
to replace in between lines with a specific character,

Code:
>cat file
this is important
>awk ' sub( substr($0, 6, 2), "x", $0) ' file
thx is important

# 4  
Old 02-28-2007
Thanks.

Actually my doubt is :

Ex: abcdefesfe98765ksksksksk
i87838383akmsm3939398*

Now i want to replace the chars 10 - 15 position as X in this 2 lines.

Output shd be:
abcdefesfeXXXXXksksksksk
878383833XXXXX3939398*
# 5  
Old 02-28-2007
modification to prev command,

Code:
awk ' sub( substr($0, 11, 5), "xxxxx", $0 )' file

# 6  
Old 02-28-2007
Thank you MM Smilie
# 7  
Old 02-28-2007
Try this if you have a very big file (say 100k records)

cut -c1-9 file > tempfile1
cut -c10-15 file | tr -cd "\n" "X" > tempfile2
cut -c15- file > tempfile3

paste -d"" tempfile1 tempfile2 tempfile3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies

2. UNIX for Dummies Questions & Answers

Grep or sed to search, replace/insert chars!

HI All Im trying to come up with an approach to finding a string, using a portion of that string to insert it on lines starting with the value "GOTO" appending to end of line after removing PT's ( See example below! ) EXAMPLE: 1. I would like to search for the line that starts with "TLAXIS/"... (7 Replies)
Discussion started by: graymj
7 Replies

3. Shell Programming and Scripting

Replace char between chars - help needed

Hello, I have a csv file with "^" as text delimiters and "|" as field delimiters. It's converted from a xls file. One record looks like this: ^Tablete Internet^|Archos|501838|^Tableta Internet ARCHOS 80 G9 ...| ... (more lines) ... "501|838"^|330.00|USD|sl|12|0|Link|^router wireless 150... (10 Replies)
Discussion started by: go0ogl3
10 Replies

4. UNIX for Dummies Questions & Answers

number of chars

I am curious why the below returns 4 instead of 3 wc -c <<<aaa Whereasa=aaa;echo ${#a} returns 3. How to get 3 using here -string operator in the above scenario Thanks (2 Replies)
Discussion started by: pandeesh
2 Replies

5. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

6. UNIX for Dummies Questions & Answers

How to replace special chars like " ' " (Apostrophe)

I'm goin to drive crazy soon, if i can not do this. I have a text file (570kb) and i have to replace the apostrophe " ' " and minus "-" with space " ". i have done it for minus: sed 's/-/ /g' aaa.txt >zzz.txt this replaced minus with space. but i can not use the same command for ' . ... (4 Replies)
Discussion started by: onculo
4 Replies

7. Shell Programming and Scripting

Replace Junk chars (Sed)

I know this has been asked previously on this forum...But I think I have a different scenario to present. I ahve a file tht looks like this (note:there are control Z and other chars tht are not visible on line with anme bowers) BB7118450 6004718 BIANCALANA =HEI BZ5842819 ... (4 Replies)
Discussion started by: alfredo123
4 Replies

8. Shell Programming and Scripting

How to convert C source from 8bit chars to 16bit chars?

I was using the following bash command inside the emacs compile command to search C++ source code: grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d' Emacs will then position me in the correct file and at the correct line... (0 Replies)
Discussion started by: siegfried
0 Replies

9. Shell Programming and Scripting

cut last 4 chars

hi i wanted to cut last 4 chars from a text file Input A-B-C-V-15-0115 A-BL-CLE-T-VALUE-0125 M-T-L-G-0115 AT-PR-PE-CCT-0135 Output 0115 0125 0115 0135 I tried cut -f - -d "-" (thinking cut -f 5- -d"-" gives 5 ot end of line so only - should give last but floped) (5 Replies)
Discussion started by: pbsrinivas
5 Replies

10. Shell Programming and Scripting

replace ascii chars without loosing it.

Hi, Can some one tell, how to replace ascii non printable TAB from the while to something, then later on replace it back to TAB. Basciallz we do bulk data processing, our processin treats TAB as new field , So I thought we can replace it with something and later on revert it. TIA (4 Replies)
Discussion started by: braindrain
4 Replies
Login or Register to Ask a Question