The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2008
edgehead edgehead is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
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
  #2 (permalink)  
Old 11-14-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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.
  #3 (permalink)  
Old 11-15-2008
edgehead edgehead is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 2
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."
thanks for the help

edgehead

Last edited by tayyabq8; 11-15-2008 at 04:35 AM.. Reason: Added code tags
  #4 (permalink)  
Old 11-15-2008
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Quote:
I get it for this example but is there a manual for all of the tokens in the " " for this sed function?
Search google for Sed tutorial or regular expressions, you'll get many free tutorials.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0