-1

i try to remove some string of my result before to send them on my array . i tried different stuff but i didn't found it :( actually in my $LOGFILE i've something like that :

STATUS          TO_CHAR(TO_TIMESTAM
--------------- -------------------
AVAILABLE       2017.10.18 18:00:30
AVAILABLE       2017.10.24 18:00:26

And i try to have only the date 2017.10.18 18:00:30

   function read_file {                                                                                                                                                                                           
      while read line;do                                                                                                                                                                                           
         arr[$i]="$line"                                                                                                                                                                                           
          i=$((i+1))                                                                                                                                                                                               
     #   $line | sed s/"-"//g | sed s/"STATUS"//g | sed s/'TO_CHAR(TO_TIMESTAM'//g | sed s/"AVAILABLE"//g | sed '/^ *$/d'                                                                                         
       done< $LOGFILE                                                                                                                                                                                              

       printf '%s\n' "${arr[@]}"                                                                                                                                                                                   
    }   
zyriuse
  • 73
  • 2
  • 10

1 Answers1

0

Would grep be acceptable?

grep -o '[0-9].*' $LOGFILE

Output:

2017.10.18 18:00:30
2017.10.24 18:00:26

Use mapfile to capture the output in an array.

$ mapfile -t arr < <(grep -o '[0-9].*' $LOGFILE)

$ echo ${arr[0]}
2017.10.18 18:00:30

$ echo ${arr[1]}
2017.10.24 18:00:26

Many thanks to this post.

Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45