validation of records2019 Community Moderator ElectionIn bash I have to ask for each row from first csv file, second csv file and the answers put to third csv fileUsing multiple awk commands within single lineHow to parse a CSV file based with groups made of specific number of rows?How to extract column name (header) from a CSV file which contains the max value in a row?Combining records from two sorted filesNeed to remove a specific column in a CSVHow do I replace tokens from one file with data from another?Validate all received files having correct datePattern recognition and summing columns between two csv/excel filesCommand to find and combine files matching a complex name pattern
Why did the EU agree to delay the Brexit deadline?
Invalid date error by date command
Is there a RAID 0 Equivalent for RAM?
Why is this estimator biased?
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
How to explain what's wrong with this application of the chain rule?
Calculate sum of polynomial roots
putting logo on same line but after title, latex
Can a Canadian Travel to the USA twice, less than 180 days each time?
What should you do if you miss a job interview (deliberately)?
How to hide some fields of struct in C?
Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?
Using substitution ciphers to generate new alphabets in a novel
Can I still be respawned if I die by falling off the map?
What is Cash Advance APR?
Non-trope happy ending?
Why does the Sun have different day lengths, but not the gas giants?
Did arcade monitors have same pixel aspect ratio as TV sets?
When were female captains banned from Starfleet?
Why is it that I can sometimes guess the next note?
Temporarily disable WLAN internet access for children, but allow it for adults
creating a ":KeepCursor" command
Does malloc reserve more space while allocating memory?
Is there a way to get `mathscr' with lower case letters in pdfLaTeX?
validation of records
2019 Community Moderator ElectionIn bash I have to ask for each row from first csv file, second csv file and the answers put to third csv fileUsing multiple awk commands within single lineHow to parse a CSV file based with groups made of specific number of rows?How to extract column name (header) from a CSV file which contains the max value in a row?Combining records from two sorted filesNeed to remove a specific column in a CSVHow do I replace tokens from one file with data from another?Validate all received files having correct datePattern recognition and summing columns between two csv/excel filesCommand to find and combine files matching a complex name pattern
Hi all i have a question that i have two files
Which contains the data where each column is
|separated . This is a csv filethe other file has data which has three rows and the third row contains the count of rows in the first file .
the data looks like below
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
Now i have to validate the row count of the csv file EXCLUDING the header which is first row in the csv file and the COUNT row in the second file .'
If the row count of the csv file matches( i am thinking of using cat file.csv|wc -l) and the count value mentioned in the second file
then i proceed further or else i move the csv file to bad a defined bad location.
shell-script
|
show 2 more comments
Hi all i have a question that i have two files
Which contains the data where each column is
|separated . This is a csv filethe other file has data which has three rows and the third row contains the count of rows in the first file .
the data looks like below
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
Now i have to validate the row count of the csv file EXCLUDING the header which is first row in the csv file and the COUNT row in the second file .'
If the row count of the csv file matches( i am thinking of using cat file.csv|wc -l) and the count value mentioned in the second file
then i proceed further or else i move the csv file to bad a defined bad location.
shell-script
but the this is is for one file my main motive is two compare the row count values from both files . here validation is most important.
– Rahul Rawat
yesterday
Is there a possibility that some fields contain newlines?
– Torin
yesterday
You have annotated the shorter file with comments. It would be easier if you could show an actual example of this file instead.
– Kusalananda
yesterday
Rahul. is the row count will be in last line ?
– Vivek Kanadiya
yesterday
yes for that i am using file2.csv| tail -1| cut -c -8 for fetching the record count. there is one issue that i need to name the file in run time as i will be receiving. files at a staging location so have to have the name stored a a variable
– Rahul Rawat
yesterday
|
show 2 more comments
Hi all i have a question that i have two files
Which contains the data where each column is
|separated . This is a csv filethe other file has data which has three rows and the third row contains the count of rows in the first file .
the data looks like below
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
Now i have to validate the row count of the csv file EXCLUDING the header which is first row in the csv file and the COUNT row in the second file .'
If the row count of the csv file matches( i am thinking of using cat file.csv|wc -l) and the count value mentioned in the second file
then i proceed further or else i move the csv file to bad a defined bad location.
shell-script
Hi all i have a question that i have two files
Which contains the data where each column is
|separated . This is a csv filethe other file has data which has three rows and the third row contains the count of rows in the first file .
the data looks like below
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
Now i have to validate the row count of the csv file EXCLUDING the header which is first row in the csv file and the COUNT row in the second file .'
If the row count of the csv file matches( i am thinking of using cat file.csv|wc -l) and the count value mentioned in the second file
then i proceed further or else i move the csv file to bad a defined bad location.
shell-script
shell-script
edited yesterday
Rahul Rawat
asked yesterday
Rahul RawatRahul Rawat
113
113
but the this is is for one file my main motive is two compare the row count values from both files . here validation is most important.
– Rahul Rawat
yesterday
Is there a possibility that some fields contain newlines?
– Torin
yesterday
You have annotated the shorter file with comments. It would be easier if you could show an actual example of this file instead.
– Kusalananda
yesterday
Rahul. is the row count will be in last line ?
– Vivek Kanadiya
yesterday
yes for that i am using file2.csv| tail -1| cut -c -8 for fetching the record count. there is one issue that i need to name the file in run time as i will be receiving. files at a staging location so have to have the name stored a a variable
– Rahul Rawat
yesterday
|
show 2 more comments
but the this is is for one file my main motive is two compare the row count values from both files . here validation is most important.
– Rahul Rawat
yesterday
Is there a possibility that some fields contain newlines?
– Torin
yesterday
You have annotated the shorter file with comments. It would be easier if you could show an actual example of this file instead.
– Kusalananda
yesterday
Rahul. is the row count will be in last line ?
– Vivek Kanadiya
yesterday
yes for that i am using file2.csv| tail -1| cut -c -8 for fetching the record count. there is one issue that i need to name the file in run time as i will be receiving. files at a staging location so have to have the name stored a a variable
– Rahul Rawat
yesterday
but the this is is for one file my main motive is two compare the row count values from both files . here validation is most important.
– Rahul Rawat
yesterday
but the this is is for one file my main motive is two compare the row count values from both files . here validation is most important.
– Rahul Rawat
yesterday
Is there a possibility that some fields contain newlines?
– Torin
yesterday
Is there a possibility that some fields contain newlines?
– Torin
yesterday
You have annotated the shorter file with comments. It would be easier if you could show an actual example of this file instead.
– Kusalananda
yesterday
You have annotated the shorter file with comments. It would be easier if you could show an actual example of this file instead.
– Kusalananda
yesterday
Rahul. is the row count will be in last line ?
– Vivek Kanadiya
yesterday
Rahul. is the row count will be in last line ?
– Vivek Kanadiya
yesterday
yes for that i am using file2.csv| tail -1| cut -c -8 for fetching the record count. there is one issue that i need to name the file in run time as i will be receiving. files at a staging location so have to have the name stored a a variable
– Rahul Rawat
yesterday
yes for that i am using file2.csv| tail -1| cut -c -8 for fetching the record count. there is one issue that i need to name the file in run time as i will be receiving. files at a staging location so have to have the name stored a a variable
– Rahul Rawat
yesterday
|
show 2 more comments
2 Answers
2
active
oldest
votes
Explanation:
file1.cvs is the file that has the count, put all the file in the same directory and then use the below script.
Script:
#!/bin/bash
count1=$(cat $1|wc -l)
for i in ./*
do
count2=$(cat $i|wc -l)
if [ $count1 == $count2 ]
then
echo "file $i matched" ## your output
else
echo "file $i is Bad file" ## your command
fi
done
Usage:
./script.sh file1.csv
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
|
show 2 more comments
Instead of piping the file into wc it's more efficient to use wc directly. I don't cat the file into tail, but just use tail directly.
Here's a script which does the comparison I believe you want.
Regarding the the loop and the filenames, you need to update your question and explain how to find the file and the count file. Or just ask a new question.
~/tmp$ cat f1
Head1,head2,head3
data1,data2,data3
data1,data2,data3
data1,data2,data3
~/tmp$ cat f1summary
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
~/tmp$ cat checkIncommingFiles
#!/bin/bash
filename=$1 # set filename
filesummary=$2 # set filesummary
wcout=$( wc -l $filename) # gets line count followed by filename
filelines=$wcout%$filename # removes filename
filelines=$(( $filelines -1 )) # subtract 1 for header
# extracts summaryCount using modified version your recipe
# file2.csv| tail -1| cut -c -8
typeset -i summaryCount # Declared as Integer to remove leading zeros
summaryCount=$(tail -1 $filesummary | cut -d"(" -f1 |cut -d" " -f2 )
# change the values
if [[ $filelines != $summaryCount ]] ; then
echo mismatch $filename has $filelines lines $filesummary has $summaryCount
else
echo goodmatch $filename has $filelines lines $filesummary has $summaryCount
fi
~/tmp$ bash ./checkIncommingFiles f1 f1summary
mismatch f1 has 3 lines f1summary has 7654
~/tmp$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507732%2fvalidation-of-records%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Explanation:
file1.cvs is the file that has the count, put all the file in the same directory and then use the below script.
Script:
#!/bin/bash
count1=$(cat $1|wc -l)
for i in ./*
do
count2=$(cat $i|wc -l)
if [ $count1 == $count2 ]
then
echo "file $i matched" ## your output
else
echo "file $i is Bad file" ## your command
fi
done
Usage:
./script.sh file1.csv
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
|
show 2 more comments
Explanation:
file1.cvs is the file that has the count, put all the file in the same directory and then use the below script.
Script:
#!/bin/bash
count1=$(cat $1|wc -l)
for i in ./*
do
count2=$(cat $i|wc -l)
if [ $count1 == $count2 ]
then
echo "file $i matched" ## your output
else
echo "file $i is Bad file" ## your command
fi
done
Usage:
./script.sh file1.csv
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
|
show 2 more comments
Explanation:
file1.cvs is the file that has the count, put all the file in the same directory and then use the below script.
Script:
#!/bin/bash
count1=$(cat $1|wc -l)
for i in ./*
do
count2=$(cat $i|wc -l)
if [ $count1 == $count2 ]
then
echo "file $i matched" ## your output
else
echo "file $i is Bad file" ## your command
fi
done
Usage:
./script.sh file1.csv
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Explanation:
file1.cvs is the file that has the count, put all the file in the same directory and then use the below script.
Script:
#!/bin/bash
count1=$(cat $1|wc -l)
for i in ./*
do
count2=$(cat $i|wc -l)
if [ $count1 == $count2 ]
then
echo "file $i matched" ## your output
else
echo "file $i is Bad file" ## your command
fi
done
Usage:
./script.sh file1.csv
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday
Vivek KanadiyaVivek Kanadiya
3379
3379
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
|
show 2 more comments
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
This would compare the length of the two files. It would not compare the length of one file with the length recorded in the other file.
– Kusalananda
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
actually this what i had thought but i have to embed this code in an ongoing script which transform the csv file . So if the validation is successful then only my rest of the script will carry on else it will move to other file for validation. I will also be getting multiple file how can i pick the files at run time and compare them according to the file received.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@vivek kanadiya the description you gave me for running the script is manual as i am running this job using oozie can (count1) variable also be picked up dynamically as the second file is being picked so i don't have to run the job over and over again as i can receive many files and this solution will be not be feasible.
– Rahul Rawat
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
@RahulRawat, I think if you can add more with what actually trying to do will help here to understand the solution!!!
– Vivek Kanadiya
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
what i am trying to convey is that while running the script ./script.sh file1.csv i have to list the file1.csv manually which i dont want . The simple solution i want is that while running the script it automatically picks up the file as there will be morethan one file to validate . so if i could use a for loop for the above. How can i do it
– Rahul Rawat
yesterday
|
show 2 more comments
Instead of piping the file into wc it's more efficient to use wc directly. I don't cat the file into tail, but just use tail directly.
Here's a script which does the comparison I believe you want.
Regarding the the loop and the filenames, you need to update your question and explain how to find the file and the count file. Or just ask a new question.
~/tmp$ cat f1
Head1,head2,head3
data1,data2,data3
data1,data2,data3
data1,data2,data3
~/tmp$ cat f1summary
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
~/tmp$ cat checkIncommingFiles
#!/bin/bash
filename=$1 # set filename
filesummary=$2 # set filesummary
wcout=$( wc -l $filename) # gets line count followed by filename
filelines=$wcout%$filename # removes filename
filelines=$(( $filelines -1 )) # subtract 1 for header
# extracts summaryCount using modified version your recipe
# file2.csv| tail -1| cut -c -8
typeset -i summaryCount # Declared as Integer to remove leading zeros
summaryCount=$(tail -1 $filesummary | cut -d"(" -f1 |cut -d" " -f2 )
# change the values
if [[ $filelines != $summaryCount ]] ; then
echo mismatch $filename has $filelines lines $filesummary has $summaryCount
else
echo goodmatch $filename has $filelines lines $filesummary has $summaryCount
fi
~/tmp$ bash ./checkIncommingFiles f1 f1summary
mismatch f1 has 3 lines f1summary has 7654
~/tmp$
add a comment |
Instead of piping the file into wc it's more efficient to use wc directly. I don't cat the file into tail, but just use tail directly.
Here's a script which does the comparison I believe you want.
Regarding the the loop and the filenames, you need to update your question and explain how to find the file and the count file. Or just ask a new question.
~/tmp$ cat f1
Head1,head2,head3
data1,data2,data3
data1,data2,data3
data1,data2,data3
~/tmp$ cat f1summary
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
~/tmp$ cat checkIncommingFiles
#!/bin/bash
filename=$1 # set filename
filesummary=$2 # set filesummary
wcout=$( wc -l $filename) # gets line count followed by filename
filelines=$wcout%$filename # removes filename
filelines=$(( $filelines -1 )) # subtract 1 for header
# extracts summaryCount using modified version your recipe
# file2.csv| tail -1| cut -c -8
typeset -i summaryCount # Declared as Integer to remove leading zeros
summaryCount=$(tail -1 $filesummary | cut -d"(" -f1 |cut -d" " -f2 )
# change the values
if [[ $filelines != $summaryCount ]] ; then
echo mismatch $filename has $filelines lines $filesummary has $summaryCount
else
echo goodmatch $filename has $filelines lines $filesummary has $summaryCount
fi
~/tmp$ bash ./checkIncommingFiles f1 f1summary
mismatch f1 has 3 lines f1summary has 7654
~/tmp$
add a comment |
Instead of piping the file into wc it's more efficient to use wc directly. I don't cat the file into tail, but just use tail directly.
Here's a script which does the comparison I believe you want.
Regarding the the loop and the filenames, you need to update your question and explain how to find the file and the count file. Or just ask a new question.
~/tmp$ cat f1
Head1,head2,head3
data1,data2,data3
data1,data2,data3
data1,data2,data3
~/tmp$ cat f1summary
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
~/tmp$ cat checkIncommingFiles
#!/bin/bash
filename=$1 # set filename
filesummary=$2 # set filesummary
wcout=$( wc -l $filename) # gets line count followed by filename
filelines=$wcout%$filename # removes filename
filelines=$(( $filelines -1 )) # subtract 1 for header
# extracts summaryCount using modified version your recipe
# file2.csv| tail -1| cut -c -8
typeset -i summaryCount # Declared as Integer to remove leading zeros
summaryCount=$(tail -1 $filesummary | cut -d"(" -f1 |cut -d" " -f2 )
# change the values
if [[ $filelines != $summaryCount ]] ; then
echo mismatch $filename has $filelines lines $filesummary has $summaryCount
else
echo goodmatch $filename has $filelines lines $filesummary has $summaryCount
fi
~/tmp$ bash ./checkIncommingFiles f1 f1summary
mismatch f1 has 3 lines f1summary has 7654
~/tmp$
Instead of piping the file into wc it's more efficient to use wc directly. I don't cat the file into tail, but just use tail directly.
Here's a script which does the comparison I believe you want.
Regarding the the loop and the filenames, you need to update your question and explain how to find the file and the count file. Or just ask a new question.
~/tmp$ cat f1
Head1,head2,head3
data1,data2,data3
data1,data2,data3
data1,data2,data3
~/tmp$ cat f1summary
date -some date mentioned
time - sometime mentioned
COUNT 00007654( random row count).
~/tmp$ cat checkIncommingFiles
#!/bin/bash
filename=$1 # set filename
filesummary=$2 # set filesummary
wcout=$( wc -l $filename) # gets line count followed by filename
filelines=$wcout%$filename # removes filename
filelines=$(( $filelines -1 )) # subtract 1 for header
# extracts summaryCount using modified version your recipe
# file2.csv| tail -1| cut -c -8
typeset -i summaryCount # Declared as Integer to remove leading zeros
summaryCount=$(tail -1 $filesummary | cut -d"(" -f1 |cut -d" " -f2 )
# change the values
if [[ $filelines != $summaryCount ]] ; then
echo mismatch $filename has $filelines lines $filesummary has $summaryCount
else
echo goodmatch $filename has $filelines lines $filesummary has $summaryCount
fi
~/tmp$ bash ./checkIncommingFiles f1 f1summary
mismatch f1 has 3 lines f1summary has 7654
~/tmp$
edited 7 hours ago
answered yesterday
X TianX Tian
7,74512237
7,74512237
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507732%2fvalidation-of-records%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
but the this is is for one file my main motive is two compare the row count values from both files . here validation is most important.
– Rahul Rawat
yesterday
Is there a possibility that some fields contain newlines?
– Torin
yesterday
You have annotated the shorter file with comments. It would be easier if you could show an actual example of this file instead.
– Kusalananda
yesterday
Rahul. is the row count will be in last line ?
– Vivek Kanadiya
yesterday
yes for that i am using file2.csv| tail -1| cut -c -8 for fetching the record count. there is one issue that i need to name the file in run time as i will be receiving. files at a staging location so have to have the name stored a a variable
– Rahul Rawat
yesterday