Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using gawk to read and manipulate multiple texts from a file

Posted on 2016-10-09
1
Medium Priority
?
118 Views
Last Modified: 2016-10-16
OS is AIX

The first part of the program check if the input  of a  particular date and group name exist in a text file. The input values need to match on that entire record in the text file. This process is similar to SQL  where clause statement.

The second part  of the program display an error message and exit the loop if there isn't a match or else continue if there is a match.  The  date format needs to change from mm/dd/yyyy to mm/dd/yy in the output of results.  The input variable n limit the number  of records that are displayed.

I'm getting an error message when I run my code. Error message: too many errors to read.

a)   Input variables in the code are
        group=hasasvmi
        date1=09/29/2016
         n=1

b)  The following is the data in the text file
       Example 1:  data in k_2016.09.29.txt :


/dev/sasdwk/hasasvmi 128 1 127  0% /sasdwk/hasasvmi  2016.09.29_11.30.27

c)   The following is an example  of the results that I want to display:



Filesystem                          GBks    Free    Used     used%                     Mt                                Date          Time
/dev/sasdwk/hasasvmi     128       1          127         0%        /sasdwk/hasasvmi        09/29/16     11:30


Here is my code:

group=hasasvmi
date1=09/29/2016
n=1
|{
read "$group"
read "$date1"
read "$n"

DISKINFO=tail $n" k_%Y.%M.%D.txt

  while IFS='' read $line

      do

        group=hasasvmi
        date1=09/29/2016

       f1='grep ^"f1" $line | awk '{print $1}''
       f2='grep ^"f2" $line | awk '{print $2}''
       f3='grep ^"f3" $line | awk '{print $3}''
       f4='grep ^"f4" $line | awk '{print $4}''
       f5='grep ^"f5" $line | awk '{print $5}''
       f6='grep ^"f5" $line | awk '{print $6}''

       If  grp= echo( $grep "$group" "$line") &&
       f7= echo ('grep " $date1" | date2= (date +%m/%d/%Y | gawk  "$line" 'BEGIN {FS=". _" OFS="/"} {print $7}'')
       && f8= (date +"%H:%M" | gawk "line" 'BEGIN {FS="_ ." OFS="."} {print $7}'')
       Then
         continue
            printf '\tFileSystem%s\tGBks%d%s\t Free%d%s\tused%d %s\tused%%s\ tMt %s\ tDate%s\ tTime%s\n'     
                   "$f1" "$f2" "$f3" "$f4" "$f5"  "$f6" "$f7" 
        else
             echo '$grp ' doesn't exist (exit)|| echo  '$f7' doesn't match the date on file for'$grp' (exit)

    fi

done <"$DISKINFO"

}

Open in new window

0
Comment
Question by:dfn48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 80

Accepted Solution

by:
arnold earned 2000 total points
ID: 41836196
What is the forma of the data you are trying to process?
If it spans multiple lines,  you need to define a multi-line match pattern, the other option is to combine the data into a single line and then perform the match.
I've not master the multi-line pattern match, so I tend to based on the pattern combine the multi-line data set into a single line and then match the data I am looking for.
I use perl for such purposes, you can use gawk, but I think you have to perform all the tests within versus reading a line by line in bash passing a line at a time to multiple grep Checks...

Your primary test igor span two lines meaning the first match might not be met effectively missing the data point.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question