The UNIX and Linux Forums  

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
While loops and awk Loriel Shell Programming and Scripting 1 10-26-2005 01:26 PM
two loops big123456 UNIX for Dummies Questions & Answers 2 10-11-2005 04:08 AM
While Loops vdc UNIX for Dummies Questions & Answers 4 05-10-2005 09:55 AM
Loops mariner UNIX for Advanced & Expert Users 2 07-01-2004 08:50 AM
loops? jonas27 UNIX for Dummies Questions & Answers 1 11-06-2001 03:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-31-2006
nymus7 nymus7 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 47
while loops

Hi

I've a file like so:

Quote:
Media1:[0]: Media ID=1232142
Media1:[1]: Type=DFRG
Media1:[2]: Date=12/03/2006
...
Media2:[0]: Media ID=1234543
Media2:[1]: Type=DFRG
Media2:[2]: Date=13/03/2006
...
Now, I want to read my file and take ex. the Media ID and the Type for each groups of Media (Media1,Media2,...,Media(n):

Code:
cat /tmp/file|\
while read FILE
do
  while $(FILE|cut -d: -f1)=Media$i
  do
    #here will be some test, ex:
    #if Media ID < 23
    #then...
  done
  let i=i+1
done

The second while loops doesn't run and I don't know how to do that.
Should I use sed, awk ? I don't must to use Perl?
And my second question is how to do a good shell script, how to know for which case which things (sed,awk,etc...) is better to use.
Yeah, it's a big questions but I really want to go further....
Best regards
  #2 (permalink)  
Old 03-31-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Quote:
Originally Posted by nymus7

Code:
cat /tmp/file|\
while read FILE
do
  while $(FILE|cut -d: -f1)=Media$i
  do
Try

Code:
while [ "$(echo ${FILE}|cut -d: -f1)." = "Media$i." ]

  #3 (permalink)  
Old 03-31-2006
nymus7 nymus7 is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 47
I've try but it doesn't run!
  #4 (permalink)  
Old 03-31-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
opss wrong code!
  #5 (permalink)  
Old 03-31-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
#! /usr/bin/ksh

exec < file
while read line ; do
        [[ "$line" = *"Media ID="* ]] && echo ${line#*=}
        [[ "$line" = *"Type="* ]] && echo ${line#*=}
done
exit 0

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