Visit The New, Modern Unix Linux Community


Need to replace 32 length string to *****


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to replace 32 length string to *****
# 1  
Need to replace 32 length string to *****

Hello,

I've a file file_1.txt

Code:
ul.ln = 'Kb' AND (il.sum = 'ec7ccc92585adac28d9b1fb5eff0473f' or length('ec7ccc92585adac28d9b1fb5eff0473f') = 7);
il.sum = '20ddc1368d588dd0b0e37c41721e05b1' OR length('20ddc1368d588dd0b0e37c41721e05b1') = 7);

I need to replace the file like below -

Code:
ul.ln = 'Kb' AND (il.sum = '*****' or length('*****') = 7);
il.sum = '*****' OR length('*****') = 7);

I tried it using sed but no luck. Please assist the ways.

Regards,
Mannu
# 2  
Please show us the sed code you tried. And, be much more descriptive about what constitutes a 32 character string. (Do things like \n count as one character or two? Are there any other "special" cases? Are strings all surrounded by single-quotes? Etc.)
# 3  
\n count as a single character. there are no more special cases and yes strings all surrounded by single-quotes.

I've used the below code but not approaching to the result - bit of success

Code:
sed "s/\(il.sum =\)\(.\{34\}\)/\ il.sum = '********************************/"


Last edited by Mannu2525; 11-07-2016 at 06:56 AM.. Reason: Adding Code
# 4  
Hi,

can you try the below one ?

Code:
sed -e 's/\([a-f0-9]\{10,\}\)/*****/g' file

gives desired output:
Quote:
ul.ln = 'Kb' AND (il.sum = '*****' or length('*****') = 7);
il.sum = '*****' OR length('*****') = 7);
Note: I used 10 in regular expression to differentiate plain words . Modify if your input contents are not fit with this .

or if your input is fixed with 32 characters as showed in input sample:
Code:
sed -e 's/\([a-f0-9]\{32\}\)/*****/g file


Last edited by greet_sed; 11-07-2016 at 08:40 AM.. Reason: Add text / code.
# 5  
Quote:
Originally Posted by Mannu2525
\n count as a single character. there are no more special cases and yes strings all surrounded by single-quotes.
If there are no other single-quotes which do not surrount strings (like in "don't know") you can do this:

Code:
sed 's/\'[^\']\{32,\}\'/\'*****\'/g'

Replace 32 (or more) non-single-quote-characters surrounded by single-quotes.

I hope this helps.

bakunin

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #465
Difficulty: Medium
A 2017 security audit of three NTP implementations, conducted on behalf of the Linux Foundation's Core Infrastructure Initiative, suggested that both NTP was less secure than Chrony.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

2. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

3. Shell Programming and Scripting

Replace Date in a fixed length file

Hello All, I working on ksh. I am using fixed length file. My file is like: ======== IXTTIV110827 NANTH AM IKSHIT ABCDEF 0617 IJAY NAND EENIG ZXYWVU 0912 AP OOK OONG PQRSTU100923 NASA DISH TTY ASDFG 0223 GHU UMA LAM QWERT 0111 ATHE SH THEW ======= From 7th to 12 is a date... (4 Replies)
Discussion started by: AnanthaDikshit
4 Replies

4. Shell Programming and Scripting

Replace strings based on position and length?

Suppose i have a file which contains thousands of records. e.g adjgmptjadmwpgjmwmd i need to replace the string from 3rd to 8th position using awk script in entire file. And also the positions will be passed as parameter. (3 Replies)
Discussion started by: laknar
3 Replies

5. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

6. Shell Programming and Scripting

Replace variable length numeric string

I have a customer who logged some cc and bank account numbers in their apache logs. I got the cc numbers x'd out with sed -e 's/args=\{16\}/args=XXXXXXXXXXXXXXXX/g' -e 's/cardnum=\{16\}/cardnum=XXXXXXXXXXXXXXXX/g'but that wasn't too difficult due to the value being 16 digits. The bank account... (7 Replies)
Discussion started by: mk4mzid
7 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. Shell Programming and Scripting

sed replace with fixed length

$ cat template s.noName $ sed "s/s.no/1/" template > out $ sed "s/s.no/100/" template >>out $ cat out 1Name 100Name 1 Name 100Name (7 Replies)
Discussion started by: McLan
7 Replies

9. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

10. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

Featured Tech Videos