1847073 Members
5203 Online
110262 Solutions
New Discussion

awk ,sed script

 
Alice_4
Occasional Advisor

awk ,sed script

i can't reali understand what those scripts mean:

1)val=`sed -n '/[~!@#$%^&*() +-={}:";<>,.?/|]/p' temp`

2)cid=`awk -F: '$1 == "'$id'"' passwd`

3)id=`awk -F: '{print $1}' temp1`

4)update=`sed "/$id/s/$cpasswd/$confirm/" passwd`

thank you...
3 REPLIES 3
Tom Geudens
Honored Contributor

Re: awk ,sed script

Hi Alice,
The easiest way to find out is to use examples :
1) Finds lines with "strange" characters in temp.
$more temp
ap
bp
+
-
/
ee
$val=`sed -n '/[~!@#$%^&*() +-={}:";<>,.?/|]/p' temp`
$echo $val
+ - /

2) Gets the line for a specific user from passwd.
$id=oracle
$cid=`awk -F: '$1 == "'$id'"' /etc/passwd`
$echo $cid
oracle:*:101:101:installation logon for oracle,,,:/oracle1/home/oracle/product/7
.2.2.3.0:/usr/bin/sh

... and so on ...
Remember that the scripts are easier to understand (for you and for us) if you also add the lines that fill up the variables ($id,$cpasswd,$confirm in the last example can mean anything for example).

Hope this gets you started.
Tom
A life ? Cool ! Where can I download one of those from ?
Christian Gebhardt
Honored Contributor

Re: awk ,sed script

Hi

1) print all lines with matching characters (don't print lines with only letters)
2) gives you the line from the file passwd (/etc/passwd??), there username matches the variable $id
3) gives you the first fields from a file (field delimiter is :), e.g if file temp1 is /etc/passwd than this line will print you all users
4) don't exactly know

Chris
Robin Wakefield
Honored Contributor

Re: awk ,sed script

Alice,

#4 is looking for the $id variable in passwd, and for any line that matches, it changes $cpasswd to $confirm. Every line is output unchanged.

However, the fact that you're equating this to a variable means that every line in the passwd file will get dumped into this variable, which may not be so useful.

Rgds, Robin