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
Validating user input is not blank MBN Shell Programming and Scripting 5 10-10-2008 07:08 AM
How can I get rid of the ` character from input file? gugs Shell Programming and Scripting 6 08-08-2008 06:51 PM
Perl code to differentiate numeric and non-numeric input Raynon Shell Programming and Scripting 11 08-04-2007 11:32 AM
validating variables (numeric) pjd1 Shell Programming and Scripting 3 11-28-2006 12:18 PM
validating input ruffenator High Level Programming 4 04-24-2002 09:30 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 01-07-2009
trichyselva trichyselva is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 65
validating a input file for numeric and character

i have a input file like this

001|rahim|bajaj|20090102

while reading the file i need to check whether the first column is a number
second column is a name

is there any methodology to check for the same

thanks in advance
  #2 (permalink)  
Old 01-07-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,362
Quote:
Originally Posted by trichyselva View Post
i have a input file like this

001|rahim|bajaj|20090102

while reading the file i need to check whether the first column is a number
second column is a name

is there any methodology to check for the same


Code:
while IFS='|' read a b c d
do
  case $a in
    *[![:digit:]]*) echo First column is not a number ;;
    *) echo First column is a number ;;
  esac

  case $b in
   *[![:alpha:]]*) echo Second column is not a name ;;
   *) echo Second column is a name ;;
  esac
done < "$FILE"

  #3 (permalink)  
Old 01-07-2009
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
using awk:
Code:
awk -F '|' '{ if($1 !~ /^[0-9]*$/) { print $1 " is not numeric in " $0; }  if($2 !~/^[a-zA-Z]*$/) { print $2 " is not alphabetic in " $0 } }' filename

Closed Thread

Bookmarks

Tags
awk regex

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 03:48 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