Sponsored Content
Top Forums Shell Programming and Scripting Searching for Log / Bad file and Reading and writing to a flat file Post 302458926 by mlpathir on Saturday 2nd of October 2010 05:17:54 PM
Old 10-02-2010
Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance:

1) search for file.log and file.bad file in a directory and read them
2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file
4) concatinate each row from bad file as "Error_Description"
5) write to a output flat file record by record
6) make sure the "number of bad record count from log file = number of records written to the output flat file"
7) below are the formats of log and bad file and output file

Log File:
=========

Load started at: 1-Oct-10 11:00:00 EDT
Database: Oracle
Tablename: abc_def_123
Datafile: /abc/def/ghi/inbound/files/file.dat


Error_Type:
-------------------------------------------------
1: 123(456) [CHAR(1)] value too long for column]
2: 123(456) [CHAR(1)] value too long for column]
3: 123(456) [CHAR(1)] value too long for column]
4: 123(456) [CHAR(1)] value too long for column]

number of bad records: 4

Bad File:
========

111 456 abc 789 2010-10-1 manager US
222 456 abc 789 2010-10-1 employee US
333 456 abc 789 2010-10-1 contractor US
444 456 abc 789 2010-10-1 partner US


Output File:
===========

Load_Start_Time Data_File_Name Error_Type Error_Description
1-Oct-10 11:00:00 file.dat 1: 123(456) [CHAR(1)] value too long for column] 111 456 abc 789 2010-10-1 manager US
1-Oct-10 11:00:00 file.dat 2: 123(456) [CHAR(1)] value too long for column] 222 456 abc 789 2010-10-1 employee US
1-Oct-10 11:00:00 file.dat 3: 123(456) [CHAR(1)] value too long for column] 333 456 abc 789 2010-10-1 contractor US
1-Oct-10 11:00:00 file.dat 4: 123(456) [CHAR(1)] value too long for column] 444 456 abc 789 2010-10-1 partner US

Last edited by mlpathir; 10-02-2010 at 07:00 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Reading a file and writing the file name to a param file.

Hi All, Not sure if this would be in a dummies sectiin or advanced. I'm looking for a script if someone has doen something like this. I have list of files - adc_earnedpoints.20070630.txt adc_earnedpoints.20070707.txt adc_earnedpoints.20070714.txt adc_earnedpoints.20070721.txt... (1 Reply)
Discussion started by: thebeginer
1 Replies

2. UNIX for Dummies Questions & Answers

Log File Writing and Reading

Hi all, I have the following shell script code which tries to sftp and writes the log into the log file. TestConnection () { echo 'Connection to ' $DESTUSERNAME@$DESTHOSTNAME $SETDEBUG if ]; then rm $SCRIPT ; fi touch $SCRIPT echo "cd" $REMOTEDIR >> $SCRIPT echo "quit" >>... (10 Replies)
Discussion started by: valluvan
10 Replies

3. Programming

I need help with file reading/writing in C

Hello everybody, I'm trying to code a program which makes the following: It sends an ARP request frame and when it gets the reply, extracts the IP address of source and writes it to a .txt file. This is gonna be done with many hosts (with a for() loop), so, the text file would look like... (2 Replies)
Discussion started by: Zykl0n-B
2 Replies

4. Shell Programming and Scripting

Reading a FLAT File - No Delimeters

Hi Folks, I have a file without any delimeters and it is a flat file. Example, my raw data looks: x25abcy26defz27ghi..... Now, could you please any one help me to program to split this into variable and create a text file. I want a output as below Name Age Number x 25 abc... (14 Replies)
Discussion started by: Jerald Nathan
14 Replies

5. Shell Programming and Scripting

Reading XML data in a FLAT FILE

I have a requirement to read the xml file and split the files into two diffrent files in Unix shell script. Could anyone please help me out with this requirement. Sample file --------------- 0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Information... (3 Replies)
Discussion started by: kmanivan82
3 Replies

6. Shell Programming and Scripting

Remove the footer from a flat file by searching a pattern

Hi, I have more than 30,000 records in a flat file. I want to remove footer from the file by searching a string pattern for the footer. Example.... let the flat file test.dat contains below records. record1 record2 record3 .. .. .. record31000 Total records 31000 I want to remove the... (6 Replies)
Discussion started by: gani_85
6 Replies

7. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

8. Shell Programming and Scripting

reading a csv file and creating a flat file

hi i have written a script for reading a csv file and creating a flat file, suggest if this script can be optimized #---------------- FILENAME="$1" SCRIPT=$(basename $0) #-----------------------------------------// function usage { echo "\nUSAGE: $THIS_SCRIPT file_to_process\n"... (3 Replies)
Discussion started by: mprakasheee
3 Replies

9. Shell Programming and Scripting

Reading and writing in same file

Hi All, Here is my requirement. I am grepping through the log files and cutting some fields from the file to generate a csv file. Now I have to check if 2nd field is having some fixed value then with the help of 4th field I have to look in same log and run another grep command to retrieve the... (11 Replies)
Discussion started by: kmajumder
11 Replies

10. Programming

Reading flat file content

is there any unix tools that can read the text files like through SQL queries? (ie in Hadoop, Impala DB support flat file query) (1 Reply)
Discussion started by: omykarshan
1 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 08:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy