linux - shell script of grep single line in bash script -


i have file following format:

123 2 3 48 85.64 85.95 park parkname location 12 2.2 3.2 48 5.4 8.9 

now write shell script extract lines file. first item each line kind of flag. different flags, make different process. see code below:

head= ` echo "$line" | grep -p "^\d+" `     if [ "$head" != "" ];    (do something...)   fi   head=` echo "$line" | grep -p "^[a-z]+" `   if [ "$head" != "" ];    (do something...)   fi 

the code works. dislike complicated way of writing 2 "if". have simple like:

if [ "$head" != "" ];    (do something...)   elif [ "$head" != "" ];    (do something...)   fi 

any thoughts?

how pure bash solution? bash has built-in regexp functionality, trigger ~ character. aware though processing huge files bash read line not yield in optimal performance..

#!/bin/bash  file=$1  while read line   echo "read [$line]"   if [[ $line =~ ^[0-9] ]];     echo '  processing numeric line'    elif [[ $line =~ ^[a-za-z]  ]];     echo '  processing text line'   fi done < $file 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -