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 > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 07-17-2008
Diabolist Diabolist is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 44
The input file:

Code:
$ cat ttt
ID .... VALUE
-------------
A001 .... 100
C003 .... 800
B002 .... 200
corrupt
data
A004 .... 300
C003 .... 800
foo .... bar
The script:
Code:
#!/bin/ksh

INPUT=ttt

{ while read LINE
do
  echo $LINE |egrep "^A|^B" > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    echo "Processing $LINE"
  else
    echo "Skipping $LINE"
  fi
done } < $INPUT
The output:
Code:
$ ./ttt.ksh
Skipping ID .... VALUE
Skipping -------------
Processing A001 .... 100
Skipping C003 .... 800
Processing B002 .... 200
Skipping corrupt
Skipping data
Processing A004 .... 300
Skipping C003 .... 800
Skipping foo .... bar
You could do a single string of commands using awk for the pattern matching, but I'm not sure how you want to process the line once you verify it's good... so this may offer the most flexibility.

Let us know if you need anything in the script explained.