Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I have a awk/sed script that I am trying to create to remove lines from a file that I thought I needed to call sed in the awk script. This is what I am trying to do in the script. Please let me know how to fix this script or if I need to modify this script another way to get what I need done. I am reading from one file and checking the user id to another file and adding a "*" to a new file and removing it from the input file. Here is the script
#!/bin/ksh
#echo "Start Processing"
while read a
dotypeset -l a
#print $j
#echo "Read disabled list: $a"
cat passwd.nis.new0 | awk -F : -v b=$a '{if ( $1 == b )
{
$2="*"
print $1":"$2":"$3":"$4":"$5":"$6":"$7
system (sed "/b/d" /ul/yyyr571/scripts/passwd.nis.new0 > /ul/yy
yr571/scripts/passwd.nis.new02)
system ("cp /ul/yyyr571/scripts/passwd.nis.new02 /ul/yyyr571/scr
ipts/passwd.nis.new0")
}}'
done < /ul/yyyr571/scripts/disabled_ID.txt
Here is the input file that I am reading from disabled_ID.txtYYYACM1
YYYAWB1
YYYAXEC
Here is the file I am looking for the user id to disable by entering in "*" to an output file and then deleting from the input file passwd.nis.new0.yyyg838:YTvlnAuhDgExw:4036:9999:Pei Jianjuo:/ul/yyyg838:/usr/bin/ksh
u00pog2:DDL4Jzr0/qil.:4042:9999:Garza Patricia O.:/ul/u00pog2:/usr/bin/ksh
yyyacm1:JIZl.2ieKWUFA:4043:9999:martinez,abel c,,:/ul/yyyacm1:/usr/bin/ksh
yyyadj2:eVfcw6hQ2kKSg:6352:125:Jacobs Al D,,,:/ul/yyyadj2:/usr/bin/ksh
yyyawb1:DCb27uFO5YlxE:6353:125:Bechard Al W,,,:/ul/yyyawb1:/usr/bin/ksh
u00pgh1:fFFM8/2sdPqx6:9200:125:Henderson Phillip G,,,:/ul/u00pgh1:/usr/bin/ksh
yyyaxec:BH0Px7HRqm7cM:5477:9999:elizalde alvaro,,,:/ul/yyyaxec:/usr/bin/ksh
yyykxy1:FMA2K5ci8kzRk:9201:224:Yi Carrie,,,:/ul/yyykxy1:/usr/bin/ksh
Please let me know if you can help me. Thanks

I may not have the requirements exactly right, but maybe this script is close. It reads a password file, writing line for line to a new file, and if the user ID is listed in the disabled file, it will change field2 in the password file to an asterisk.
This code assumes (maybe incorrectly) that the password file always has lowercase user IDs, and that the user ID in the disabled list can be upper, lower or mixed case.
awk -F: 'BEGIN {
while ((getline < "disabled_ID.txt") > 0)
disable_list[tolower($1)] = 1
OFS=":"
}
{if ($1 in disable_list)
$2="*"
}' passwd.nis > passwd.nis.new

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |