![]() |
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 |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ftp checking | ust | Shell Programming and Scripting | 0 | 07-10-2008 03:30 AM |
| Ksh Checking if string has 2 characters and does not contain digits? | developncode | UNIX for Dummies Questions & Answers | 1 | 04-08-2008 04:19 PM |
| EOF checking the below | ramkrix | High Level Programming | 10 | 03-11-2008 01:43 AM |
| Checking for PXE | maestro@altiris | SUN Solaris | 5 | 05-25-2004 01:06 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Checking for certain characters
Could anyone help with the following enquiry.. i have a file in the following format:
ID .... VALUE A001 .... 100 B002 .... 200 A004 .... 300 B006 .... 100 A997 .... 200 B776 .... 400 It is in a column format, but I want to check that the ID field always begins with with and A or B character this is my logic thus far: If Character 1 DOES NOT equal A or B then display error message else carry on doing what you want fi not really sure how to chech that character 1 of each line does not equal A or B habe tried following with no no joi If [ ! grep '^A' $file || ! grep '^B' $file ] then print "error" else print "it works" fi but the above does not work i believe it to logic as my unix understanding not great, please assist. |
|
||||
|
BTW, you could also bypass putting this into a script.
Code:
awk '/(^A)|(^B)/ {num++} END {if(num > 0);printf("%d instances of A,B exist\n", num);}' column
|
|
||||
|
Ok the above only tell me how many times A or B where in there. I require it to send an error message if a C exist or otherwise its fine to continue processing file.. hope that makes more sense
|
|
||||
|
The input file:
Code:
$ cat ttt ID .... VALUE ------------- A001 .... 100 C003 .... 800 B002 .... 200 corrupt data A004 .... 300 C003 .... 800 foo .... bar 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
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 Let us know if you need anything in the script explained. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|