![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
$
|
|
#3
|
|||
|
|||
|
thanks sir Perderabo, it works in aix, but not in solaris
|
|
#4
|
||||
|
||||
|
Invinzin, on Solaris you may have gawk available.
$ gawk -F: -v OFS=: '{$3="yes";print}' data |
|
#5
|
|||
|
|||
|
thanks i use nawk
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
Your script shows 'awk' & not 'nawk' ?!
|
||||
| Google The UNIX and Linux Forums |