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
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:
#!/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."
thanks for the help
edgehead
Search google for Sed tutorial or regular expressions, you'll get many free tutorials.