Question: 1 . Create a shell script file called asgn 0 5 . sh 2 . Complete this newly created shell script asgn 0 5 .
Create a shell script file called asgnsh
Complete this newly created shell script asgnsh The invocation of the shell script is as follows: asgnsh sample.log useractionadditional 'location.lat,data.amount'
where
$ is the log file;
$ is a regular expression to filter the entries by matching specific log field keys. eguseractionadditional: This will match any fields that start with user, or contain action, or contain additional. If an entry doesnt contain any fields matching the pattern, discard it;
$ is the list of JSON fields separated by comma locationlat and data.amount will extract the lat value from the location JSON object and amount value from the data JSON object, if present
The script asgnsh needs to do the followings: i Parse Each Log Entry: Extract both JSON and keyvalue pairs from each entry. ii Standardize Missing Fields: For any missing fields in an entry, set the value to NA iii. Filter by Regular Expression: Use $ to identify entries containing those fields that match the provided regex pattern. If an entry doesnt contain any fields matching the pattern, discard itNote: if an entry doesnt contain any fields specified in $ but contains fields specified in $ discard it iv Extract JSON Field: Use $ to extract the specified JSON fields if present v Generate a CSV Report: i Columns should include all unique keys from both JSON and keyvalue pairs. ii Missing values should be filled with NA iii. Ensure that columns appear in alphabetical order.
Sample Run: The expected output for executing asgnsh sample.log useractionadditional 'location.latdataamount' shown below: action,additionalinfo,dataamount,locationlat,userid loginNANA purchase,Promo code applied,NA NANANA logoutNANANA purchase,NANA
sample.log file below a few lines example
timestampT:: userid locationcountry:US"city":"New York","lat":"long": actionlogin timestampT:: userid datavalue:"type":"purchase","amount": actionpurchase additionalinfoPromo code applied
timestampT:: locationcountry:UK"city":"London","lat":"long": userid datavalue:"type":"login
timestampT:: userid actionlogout statussuccess timestampT:: userid datavalue:"type":"purchase","amount": actionpurchase
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
