![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with while loop in BASH shell | npatwardhan | Shell Programming and Scripting | 6 | 11-09-2008 10:57 AM |
| bash array problem | yagnesh | Shell Programming and Scripting | 1 | 08-19-2008 02:48 AM |
| Bash: bad substitution problem...pls help! | xfouxs | UNIX for Dummies Questions & Answers | 1 | 11-23-2007 05:48 PM |
| Bash while loop problem | Kweekwom | Shell Programming and Scripting | 5 | 07-23-2007 12:49 AM |
| bash script problem | fnoyan | Shell Programming and Scripting | 1 | 02-15-2004 10:51 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Bash problem
Hello there, I'm a beginner in bash programining and I have a problem with the interpretetion of the code: sed -e "s/\([^:]*\):.*/\1/" in this for loop:
for process in $(sed -e "s/\([^:]*\):.*/\1/" /etc/passwd) thx for any help edgehead |
|
||||
|
The sed statement returns the first field \1 or group of characters that is not a :
In other words the : acts a as a field separator. The first field of /etc/passwd is the username. So "for process in first field name of all records in /etc/passwd" is a start of a for loop that reads thru the passwd file, that sets the process variable equal to each of the usernames in the passwd file, in turn. |
|
||||
|
thanks Jeff for the fast reply I did not expect it so fast
![]() I get it for this example but is there a manual for all of the tokens in the " " for this sed function? I have another problem. I have written a program which prints me the latest changed file in the directory and his subdirectories but i get a error and i don't know why! Here is the code: Code:
#!/bin/bash
#Check for number of parametersd
if [ $# -ne 1 ]; then
echo "USAGE: $0 path"
exit 0
fi
#Go through all directories
for directory in $`ls $1 -R | grep -e ":$" | sed -e "s/://g"` do
line=0
filename=""
fileinfo=""
#Get information for the file that was most recently modified
for entry in $(ls $directory -lt | grep -e "-"); do
if [ $line -gt 8 ]; then
break
fi
if [ $line -gt 4 ]; then
if [ $line -lt 8 ]; then
fileinfo="$fileinfo $entry"
fi
fi
if [ $line -eq 8 ]; then
filename=$entry
fi
let line=line+1
done
if [ "$filename" != "" ]; then
s=`find $1 -newer $directory/$filename`
if [ "$s" = "" ]; then
echo "$directory/$filename $fileinfo"
exit 0
fi
fi
done
echo "No files found."
edgehead Last edited by tayyabq8; 11-15-2008 at 04:35 AM.. Reason: Added code tags |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|