The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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

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 07-17-2008
fsahog fsahog is offline
Registered User
  
 

Join Date: Apr 2006
Location: Northern Virginia
Posts: 23
That shell script above - you see where it displays "error" - if you make the script in a file with the execute bit set, you can run it. Use the portion that shows an error, i.e. "Skipping line" - and say, for example, "exit 1". Then at the end, assuming it didn't hit there, say "exit 0". Remove the printing where it's OK on A/B. Then your script exit value is zero/non-zero and you can use it as a test. Have it's input be from standard input, and it can "filter" for you. I realize this might be lots of theory and not enough specifics. If so, I could make it so and give you exact examples. Other folks here could too, I imagine. If you need it and no one has by the time I get back here, I'll do it.
  #2 (permalink)  
Old 07-20-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
Code:
awk 'NR > 1 { if( /^A/ || /^B/ ) { printf "%s - Correct - Carry on with what you are doing!\n", $0 } else { printf "Error\n" } }' filename
  #3 (permalink)  
Old 07-21-2008
SAMZ SAMZ is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 18
Thanks for all the above help, but let me clarify the need of what is required to see if anyone can assist further.
Currently as stated i have teh following file called TEST1.CSV

ID ,, VALUE
A001 ,, 100
B002 ,, 200
A004 ,, 300
B006 ,, 100
A997 ,, 200
B776 ,, 400



This file needs to be processed but only if all the ID's are correct (that means only if the IDs begin with an A - B charcter.
If the ID begins with any character other A or B the process needs to exit out the script with error message.

What i would like is the following:

IF [begining of row is not A or B] THEN
print error message
exit 1
END IF

No else required as if the only A and B the IF statement will end succesfully leading the process scripting afterwards.
So any thoughts, not really as complex as previously thought???
  #4 (permalink)  
Old 07-21-2008
SAMZ SAMZ is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 18
OK i have found this to be teh best solution thus far, anyone with any better thoughts

if [ `cat TEST1.CSV | egrep -v '^A|^B' | wc -l` -gt 0 ]
then
echo "error message"
exit 1
fi
  #5 (permalink)  
Old 07-21-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
SAMZ, until now you didn't tell us what you really want to achieve. The logic you used is ok, but - depending on what you want to do, the part inside "carry on doing what you want" - there may or may not be better solutions. We are able to help you only if we know exactly what you want to achieve.

Maybe your way (that is: to do it in shell script language) is good, because the shell is best suited to what you want to achieve. The other solutions (awk, sed, ...) may or may not be better suited than your solution because the respective tools may or may not be better suited to what you want to do - to finally assess this question we would need to know what you want to do.

I hope this helps.

bakunin
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 08:04 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