Visit Our UNIX and Linux User Community


Comparing one file header with another file header


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing one file header with another file header
# 1  
Old 11-09-2010
Question Comparing one file header with another file header

Hi Experts,

In our project we have requirement where in we have to compare header of one file with header in the parameter file.
There are 20 files which we ftp from one site. All this files have different header.
We are comapring this file with our parameter file(which is having the header fields in the format what we are expecting) Smilie
If the ftp file header format matches with the parameter file format then we are processing these file, if not we are renaming it Unprocess_file.

The parameter file structure is :
Code:
FileName|Daily_Process|Expected_Header|TABLE_NAME
acct_details.csv|Y|ACCT_NBR,UserName,Status,Date|ACCT_DETAILS
address_info.csv|Y|ACCT_NBR,ADD_DETAILS,STATE,ZIP|ADDRESS_INFO

Now the problem is the one the of the source file header is coming as :

Code:
ACCT_NBR, ADD_DETAILS, STATE, ZIP

That is it has got spaces in between the column names.
How can i compare these file with existing parameter file. If i change the parameter file (that is added space in between the columns ) still its not working. Smilie

How can I handle this scenario? Smilie

Thanks in Advance!!
# 2  
Old 11-09-2010
Code:
 
h=$( sed '
  s/, */,/g
  q
 ' $data_file )
 
emsg=
 
for f in $( sed '
  /^'"$file_type"'|/!d
  s/.*|\(.*\)|.*/\1/
  s/, */ /g
 ' $parm_file )
do
 if [ "$f" != "${h%%,*}" ]
 then
  emsg="$emsg, $f is ${h%%,*}"
 fi
 h=${h#*,}
done
 
if [ "$emsg" != "" ]
then
 echo "File error$emsg." >&2
 mv $data_file Unprocess_file.$data_file
fi

# 3  
Old 11-09-2010
MySQL

Thanks for the immediate reply!!
Its working !!Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #877
Difficulty: Medium
A real-time operating system (RTOS) is an operating system (OS) intended to serve real-time applications that process data as it comes in, typically without buffer delays.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

Extraction of header columns and comparing it with Header_format

set -x for file in /Src/MEDIA_ASSET/*.csv; do Header_Format = 'VariantNumber|ERP_SYSTEM_CD|MediaType' FILESTATUS = GOOD File_Header = $(cut -d'|' -f1-3 ${file}|head -1) do if ; then ${FILESTATUS} = GOOD else ${FILESTATUS} = BAD break fi done ... (3 Replies)
Discussion started by: spidy
3 Replies

3. Shell Programming and Scripting

Manipulate all rows except header, but header should be output as well

Hello There... I have a sample input file .. number:department:amount 125:Market:125.23 126:Hardware store:434.95 127:Video store:7.45 128:Book store:14.32 129:Gasolline:16.10 I will be doing some manipulations on all the records except the header, but the header should always be... (2 Replies)
Discussion started by: juzz4fun
2 Replies

4. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

5. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

6. Shell Programming and Scripting

Renaming all header to specific header pattern

Input #HAC0253 EFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #BASFS12 EFVEFVHIJEFVEFVTOPKEFVOPKTHIJTTHIJOPK #ACG5115 TEFVEFVOIJEFVHIJHIJOPKOPKHIJHIJTTEFVEFVOPKTTEFVEFVOPKHIJOPKOPKOPK #ECG5114 IJTOPKHIJEFVOEFVEFVOPKTTEFVEFVOPKHIJOPKOPKOPK . . Output (5 Replies)
Discussion started by: patrick87
5 Replies

7. Shell Programming and Scripting

insert a header in a huge data file without using an intermediate file

I have a file with data extracted, and need to insert a header with a constant string, say: H|PayerDataExtract if i use sed, i have to redirect the output to a seperate file like sed ' sed commands' ExtractDataFile.dat > ExtractDataFileWithHeader.dat the same is true for awk and... (10 Replies)
Discussion started by: deepaktanna
10 Replies

8. Shell Programming and Scripting

Split large file and add header and footer to each file

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (1 Reply)
Discussion started by: ashish4422
1 Replies

9. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies

Featured Tech Videos