Computing.Net > Forums > Unix > Awk/Sed Question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Awk/Sed Question

Reply to Message Icon

Name: Troy Blangin
Date: July 30, 2007 at 09:17:01 Pacific
OS: HP-UX 11i
CPU/Ram: PA-RISC
Product: rp8400
Comment:

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
do

typeset -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.txt

YYYACM1
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



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: July 30, 2007 at 14:35:23 Pacific
Reply:

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="*"
 print
}' passwd.nis > passwd.nis.new


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Awk/Sed Question

Different results from awk, sed, tr www.computing.net/answers/unix/different-results-from-awk-sed-tr/7711.html

awk/sed help www.computing.net/answers/unix/awksed-help/6553.html

Editing a file without awk or sed www.computing.net/answers/unix/editing-a-file-without-awk-or-sed/5437.html