The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-25-2007
Registered User
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 67
sed and awk

Good morning,

Any idea how to repalce this sed or awk?

file:10:no:1011
file:10:file:1011
data:10:say:1011
data:10:data:1011


output:
file:10:yes:1011
file:10:yes:1011
data:10:yes:1011
data:10:yes:1011
Reply With Quote
Forum Sponsor
  #2  
Old 12-25-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Good evening!

One way...
Code:
$ cat data
file:10:no:1011
file:10:file:1011
data:10:say:1011
data:10:data:1011
$ awk -F: -v OFS=: '{$3="yes";print}' data
file:10:yes:1011
file:10:yes:1011
data:10:yes:1011
data:10:yes:1011
$
Reply With Quote
  #3  
Old 12-25-2007
Registered User
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 67
thanks sir Perderabo, it works in aix, but not in solaris . actually it was intended for solaris, but thanks a lot.
Reply With Quote
  #4  
Old 12-25-2007
DeepakS's Avatar
Registered User
 

Join Date: Aug 2006
Posts: 60
Invinzin, on Solaris you may have gawk available.

$ gawk -F: -v OFS=: '{$3="yes";print}' data
Reply With Quote
  #5  
Old 12-25-2007
Registered User
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 67
thanks i use nawk
Reply With Quote
  #6  
Old 12-25-2007
Registered User
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 67
hi sir's,
here's the problem i encountered regarding w/ awk. Hope someone could help. below works for me.

$cat passwdlist
root:6GNlhvGxH3jOk:6445::::::
daemon:asasda:6445::::::
bin:NP:6445::::::
sys:NP:6445::::::


nawk -F: -v OFS=: '{
if($1 ~ "root" || $1 ~ "daemon" ){print $1,"yes:" $2,$3,$4,$5,$6,$7,$8}
else { print $0 }
}' passwdlist > new2

output :

root:yes:6GNlhvGxH3jOk:6445:::::
daemon:yes:asasda:6445:::::bin:NP:6445::::::
sys:NP:6445::::::


But when i try to embed it in my script it doesnt work,

$ cat test1
rm file1
rm new2
for x in `cat userlist`
do

for i in `cat passwdlist | grep -w $x | awk -F: '{print $2}'`
do
a=NP
if [ $a != $i ]
then
echo " $x are not equal to NP" >> file1
fi

for n in `cat file1|awk '{print $1}'`
do
awk -F: -v OFS=: '{
if($1 ~ "$n" ){print $1,"yes:" $2,$3,$4,$5,$6,$7,$8}
else { print $0 }
}' passwdlist > new2


done
done
done
clear
cat new2


of course i changed root, daemon to $n, i dont want to declare those vaules, what if i have plenty of accoutns that i want to disabled. Hope someone could get it
Reply With Quote
  #7  
Old 12-25-2007
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 105
Your script shows 'awk' & not 'nawk' ?!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0