Script to check the string in a file and print an attribute in the message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check the string in a file and print an attribute in the message
# 1  
Old 05-12-2017
Script to check the string in a file and print an attribute in the message

Hi,

I am new to shell scripting and got a task to complete.

Task is : we have a log file where in i need to traverse through the whole file to check the string "Person Type missing in message" and after that i need to get EMPLID=xxxxxx from the file and print details in a different file.

Below is snippet of the message in log file ( highlighted in color) which i need from the file

Code:
2017-05-09 20:15:51,713 [asyncDelivery111] [ConnectorBean] [] - ConnectorBean/findEventType Attention ::TEAM
The message with Message IDID:414d5120455342459080862020202020632eee58ffe83028is being ignored::For create event type, Person Type missing in messageFind user attributes in next line
{BUSINESS_TITLE=, PER_TYPE=, PayGroupCode=, LaborType=, RehireDate=, WORKSHIFT_CD=, POSITION_NBR=, HRServiceDate=2017-05-30, FIRST_NAME=xxxx, PeopleSoftID=, HOME_EMAIL_ADDRESS=, JOB_DESCRIPTION=, PER_STATUS=, FAX=, HOME_PHONE=, COMPANY=, WORK_PHONE=, Work Address Line One=, Country=, LAST_NAME=xxxx, PREF_MIDDLE_NAME=, StatusReason=GENERAL_EVENT_SUBCATEGORY-6-66, MANAGER_ID=, DIVISION=, WorkerTypeName=, PREF_FIRST_NAME=xxx, TMS_DEPT_GRP=, EMPL_CLASS=, MAIL_DROP=, DEPTID=, MatrixManager=, COMPANY_DESCR=, EMAIL_ADDR=, DEPT_DESCR=, DEPT_GROUP_ID=, PREF_LAST_NAME=xxxx, WorkerTypeCode=Team Member, UNION_CD=, BUSINESSCELL=, HRSeniorityDate=2017-05-22, PREF_SUFFIX_NAME=, DIVISION_DESCR=, SOX_TRANSFER_FLAG=N, Zip Code=, JOBCODE=, BadgeID=, GRADE=, EMPL_STATUS=A, NAME_SUFFIX=, Work Addrress Line Two=, City=, LOCATION=, LOCATION_DESCR=, JobLevel=, State=, MOBILE=, MIDDLE_NAME=, EMPLID=000112, TMS_PAGER=, REGION_CODE=}

Please let me know, how can i accomplish this.

Thanks in advance

Last edited by Don Cragun; 05-12-2017 at 05:23 AM.. Reason: Add CODE and ICODE tags again.
# 2  
Old 05-12-2017
Please:
  1. use CODE tags when displaying sample input, sample output, and code segments so we can tell how many lines are in your sample data, see whether or not there are multiple adjacent whitespace characters, and (when there are multiple column positions occupied by whitespace characters) determine whether those characters are tabs or multiple spaces,
  2. tell us what operating system you're using,
  3. what shell you're using,
  4. explain the format of your input data (Are there always three lines per record in your input file? Is the 1st string you're looking for always on the 2nd line in a record? Is the 2nd string you're looking for always in the same comma separated field on the 3rd line in a record? Is there only one record in each log file? What is/are the name(s) of your log file(s)?),
  5. explain the format of the output you want to produce,
  6. show us the output (exactly) you hope to produce from your sample input file (in code tags),
  7. tell us the name of the output file you hope to produce,
  8. and show us what you have tried to solve this problem on your own.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to match string and print status

Dear team, Need support to built awk script for below requirement Input file LOTC cluster state: ------------------- Node safNode=SC_2_1 joined cluster | Node safNode=SC_2_2 joined cluster | Node safNode=PL_2_3 fail cluster | AMF cluster state: ------------------... (16 Replies)
Discussion started by: shanul karim
16 Replies

2. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

3. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

4. Programming

Python: Check 2 text files for string and print contexts

I have 2 text files: cities.txt San Francisco Los Angeles Seattle Dallas master.txt Atlanta is chill and laid-back. I love Los Angeles. Coming to Dallas was the right choice. New York is so busy! San Francisco is fun. Moving to Boston soon! Go to Seattle in the summer. ... (0 Replies)
Discussion started by: pxalpine
0 Replies

5. Shell Programming and Scripting

Linux Shell Script to check for string inside a file?

This is what I have so far grep -lir "some text" * I need to check all files on the system for this text, if the text is found I need to change the file permissions so only ROOT has read and write access. How can this be done? (3 Replies)
Discussion started by: mapleleafs89
3 Replies

6. Shell Programming and Scripting

How to Check given string is number in shell script?

Hi, Can anyone help me out to check whether the input argument is number? Example: REQUEST_ID="123456" I need to check the REQUEST_ID value is number or string. Thanks in Advance Regards BS (6 Replies)
Discussion started by: balajiora
6 Replies

7. Shell Programming and Scripting

bash script to check the first character in string

Hello would appreciate if somebody can post a bash script that checks if the first character of the given string is equal to, say, "a" thnx in advance (2 Replies)
Discussion started by: ole111
2 Replies

8. Shell Programming and Scripting

check for not null string in file

Hi, If, in a text file a string is expected at a certain fixed position(for eg at position 5 or from 5-10 on every line) how to check whether data is present on that position or not? Thnx in advance (6 Replies)
Discussion started by: misenkiser
6 Replies

9. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies

10. Linux

File attribute Help please

Could anyone help i have a question that i have a problem with for my home work it is, How do i change file permissions in a command line enviromet thanx (1 Reply)
Discussion started by: Cube3k
1 Replies
Login or Register to Ask a Question