processing the file based on the string in the file.
Moderators: chulett, rschirm, roy
processing the file based on the string in the file.
Hi all ,
Iam bit newbie to the shell scripting. And my requirement is as folows
Iam having txt file and it contains data as :::
HEADER_FILE;SPD;TCE;20080417 11:20
118982_101;20RTG STD;GRE;118982_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
111159_101;20RTG STD;GRE;111159_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
036964_101;20RTG STD;GRE;036964_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
015402_101;20RTG STD;GRE;015402_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
FOOTER_FILE;4
I want to search for a string FOOTER_FILE in the last line of the line. If the string exists then i need to process the file. Else the file need not to be processed.
Can you share the piece of code for the above requirement.
Your help is greatly appreciated.
Thanks in advance.
Iam bit newbie to the shell scripting. And my requirement is as folows
Iam having txt file and it contains data as :::
HEADER_FILE;SPD;TCE;20080417 11:20
118982_101;20RTG STD;GRE;118982_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
111159_101;20RTG STD;GRE;111159_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
036964_101;20RTG STD;GRE;036964_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
015402_101;20RTG STD;GRE;015402_101;ATK;1;1;01012008 00:00;01012100 00:00;1;1;STD;0;
FOOTER_FILE;4
I want to search for a string FOOTER_FILE in the last line of the line. If the string exists then i need to process the file. Else the file need not to be processed.
Can you share the piece of code for the above requirement.
Your help is greatly appreciated.
Thanks in advance.
Is this in an attempt to ensure a file, which is being transferred to your system via ftp, is complete?
Me, I'd grep for the footer record and count the result:
0 = not there, 1 = there. Easy to make a decision from there.
Me, I'd grep for the footer record and count the result:
Code: Select all
grep FOOTER_FILE <filename> | wc -l
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Adding to Craig's post to make it bulletproof:
if that string could show up elsewhere in the file
Code: Select all
tail -1 <filename> | grep FOOTER_FILE | wc -l
There should be no spaces between the VARIABLE (count) , the assignment operator ( = ) and the operand (`grep -i "FOOTER_FILE" /home/user/dsstage/test/Input.txt|wc -l`). I am not sure if it is copy-paste or phpBB, but I can see spaces in both posts.
Copy this line and execute
count=`grep -i "FOOTER_FILE" /home/user/dsstage/test/Input.txt|wc -l`
then execute
echo $count
Ping back if it still throws error
Copy this line and execute
count=`grep -i "FOOTER_FILE" /home/user/dsstage/test/Input.txt|wc -l`
then execute
echo $count
Ping back if it still throws error