shell script to mask


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to mask
# 1  
Old 08-26-2008
shell script to mask

I have a file which has huge number of rows.

I have to mask only few rows at a particular position lets say 12th to 19th i have to replace with X's (XXXXXXX)

I am reading the file and even checking the conditions, but I am not sure how I can replace the text

my program

while read lines
do
b=`echo "$lines" | awk '{print substr($0,1,3)}'`
if [ "$b" = "0 " ]; then
?????????????????????
fi
done < maintest


maintest is my file

I dont want to create a temp file and place all the lines in it .


Please help
thanks

# 2  
Old 08-26-2008
Code:
awk '$12=$19="XXX"' file > new_file

# 3  
Old 08-26-2008
Can it be done without using a new_file ?

I mean updating the same file is that possible?

Please Advice

Thanks
# 4  
Old 08-26-2008
A suffiently big file, not very well.

Unless you did it in C - and use the rewrite command. This will work only if the new data is the same size as the old.

Perhaps a C class would be the way to go.

Quote:
Originally Posted by prassu
Can it be done without using a new_file ?

I mean updating the same file is that possible?

Please Advice

Thanks
# 5  
Old 08-26-2008
thanks for your update,

I would probably do this for now
read every line paste it in the new file if it doesn't match with my conditions.

if it does match paste the $line | awk command into the file

Thanks and really appreciate the timely responses.
# 6  
Old 08-26-2008
Quote:
Originally Posted by prassu
Can it be done without using a new_file ?

I mean updating the same file is that possible?

Please Advice

Thanks
With GNU sed you can uptate file in place using the -i option.
Code:
> cat prassu.dat
123456789012345678901234567890
----.----+----.----+----.----+
abcdefghijklmnopqrstuvwxyz____
> sed -i 's/\(.\{15\}\)..../\1XXXX/' prassu.dat
> cat prassu.dat
123456789012345XXXX01234567890
----.----+----.XXXX+----.----+
abcdefghijklmnoXXXXtuvwxyz____
>

Jean-Pierre.
# 7  
Old 08-27-2008
Unfortuantely,
I am not able to use the sed -i but

I am also getting error while using the following command
$lines has the string I want to modify

write=`echo "$lines" | awk '$12=$19="XXX"'`
echo "$write" | cat >>test

Am I doing right ?

I even tried this.

write=`echo "$lines" | awk '{print substr($0,1,12) "XXXXXXX" substr($0,19)'`

Please suggest
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep match a mask

Hi all, Im trying to use grep to match a exact mask where some characters are known and some are not. for example: j***n@email.com in this case the length is known and the position of the unknown characters are know (and will be ) any idea how I can do this? the file list is not just... (3 Replies)
Discussion started by: flamer
3 Replies

2. Red Hat

How to compare file mask?

hey, i have an array which stores different type of file name like File_123.csv, File_as34.csv File_dff.csv that is after undersore it can be a numeric value or alphanumeric or alphabets and it can be different values. now what i have to do is to compare the values after underscore and... (1 Reply)
Discussion started by: ramsavi
1 Replies

3. UNIX for Dummies Questions & Answers

What is mask and effective right mask in setfacl?

Hi Guys, can someone explain what is mask and effective right mask in setfacl and getfacl command with example, unable to get it. (3 Replies)
Discussion started by: Jcpratap
3 Replies

4. Red Hat

Samba create mask and dir mask on RHEL 4.8

Hi Experts, I'm using samba -3.6.1 on Red Hat Enterprise Linux ES release 4 (Nahant Update 8) ,all seems ok. The issue im facing is as follows. When ever a user creates a file via windows explorer the permissions assgined to the file are as follows -rw-rwxr--+ 1 tom group2 0 Mar 9... (1 Reply)
Discussion started by: maverick_here
1 Replies

5. UNIX for Dummies Questions & Answers

how to mask the password ?

Hi All, i am executing peoplesoft sqr command from unix prompt which has the unix id/password as parameter along with other parameters. i want to show whole command in log file but want to mask the id/password field. this command i am executing in shell script. Please suggest.. >sqr sqrname... (2 Replies)
Discussion started by: avi.coep
2 Replies

6. Shell Programming and Scripting

Need to Mask Data

I have an requirement. There is a file which has the below contents Unix|123|17-01-2010 .... .... .... .... and so an now each letter has a corresponding predefined mapping letter in order to mask the original data.(for example U = A, n=b, i=c, x=d, same like number 1=9,2=8,3=7. Also... (8 Replies)
Discussion started by: ksmbabu
8 Replies

7. Shell Programming and Scripting

mask ID number

HP-UX 11i v2. #!/bin/sh Hi all. I have a flat file like this with lines like this: |07/19/07|08:26AM|1|CupsCoffee|CupsCo|989898989 |Doe, John Y |THE PLUS CARD - Price| | |Y| | 2.00| I would like to replace the id number (field 6) with a masked... (3 Replies)
Discussion started by: lyoncc
3 Replies

8. IP Networking

Changing the mask

What is the command to change the mask to 255.255.255.0 The system was set up incorectly and the mask needs to be corrected (1 Reply)
Discussion started by: kkinnon
1 Replies

9. Programming

password mask in C

Hi, Could any one help me to write a C program for password mask with ******. I mean whatever word i will type that will show on the screen as ***** and should store the correct value in a variable. Thanks in advance Krishna (5 Replies)
Discussion started by: krishna
5 Replies

10. IP Networking

Subnet mask

Hi, I have about 30 computers for users with subnet mask x.x.x.0, and 25 computers for workers with s.m. x.x.x.128. My server has a s.m. x.x.x.128 so with workers computers I can see my server and all the computers in that s.m., but I can't see the server from the users computers and I need to see... (7 Replies)
Discussion started by: Z0DiaC
7 Replies
Login or Register to Ask a Question