bash looping and extracting of the fragment of txt file

后端 未结 3 1667
长情又很酷
长情又很酷 2021-01-23 13:26

I am dealing with the analysis of big number of dlg text files located within the workdir. Each file has a table (usually located in different positions of the log) in the follo

3条回答
  •  再見小時候
    2021-01-23 13:50

    I would suggest processing using awk:

    for i in $FILES
    do
        echo -n \""$i\": "
        awk 'BEGIN {
               output="";
               outputlength=0
             }
             /(^ *[0-9]+)/ {                                    # process only lines that start with a number
               if (length(substr($10, 2)) > outputlength) {     # if line has more hashes, store it
                 output=$0;
                 outputlength=length(substr($10, 2))
               }
             }
             END {
               print output                                     # output the resulting line
             }' "$i"
    done
    

提交回复
热议问题