LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2013, 03:10 AM   #31
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled

thx reply ,

I tried to merge the script to as below

-------------------------------------------------
#!/bin/bash

MyString="abc\.)%@"

Total=0
GetData () {
AwkMyString="$( sed -e 's/[\/*?.+{}]/\\&/g' -e 's/[[]/\\&/g' -e 's/[]]/\\&/g' <<< "${MyString}" )"
for File in *.txt;do
Date="$(date "+%b %Y" --date="${File:4:6}01")"
awk 'BEGIN{C=0}{for (i=1;i<=NF;i++) if ( $i ~ /'${AwkMyString}'/ ){C++}} END{printf "%s %s?","'"${Date}"'",C}' "$File"
done
}
while read -d '?' Month Year Count;do
TableDate+=("${Month} ${Year}")
TableCount+=("${Count}")
done <<< $(GetData)

printf "%10s" "|"
for i in $(seq 0 $(( ${#TableDate[@]} - 1 )) );do
printf "%s |" "${TableDate[$i]}"
done
printf " Total |\n"


for i in $(seq 0 $(( ${#TableCount[@]} +1 )) );do
printf "=========|"
done
printf "\n"
printf "%10s" "|"
for i in $(seq 0 $(( ${#TableCount[@]} - 1 )) );do
printf "%*s%*s" $(( $((11 + ${#TableCount[$i]}))/2 )) "${TableCount[$i]}" $(( $((10 - ${#TableCount[$i]}))/2 )) "|"
done
for i in $(seq 0 $(( ${#TableCount[@]} - 1 )) );do
Total=$(( ${TableCount[$i]} + ${Total} ))
done
printf "%*s%*s" $(( (11 + ${#Total})/2 )) "${Total}" $(( (10 - ${#Total})/2 )) "|"

-------------------------------------------------

but got the result as below , the heading is duplicated , I tried many modification but still not work , would you help to fix it ? thanks

|Oct 2013 | Total |
=========|=========|=========|
| 14 | 14 | |Oct 2013 |Oct 2013 | Total |
=========|=========|=========|=========|
| 14 | 14 | 28

Last edited by byran cheung; 11-28-2013 at 09:14 AM.
 
Old 11-28-2013, 05:28 AM   #32
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
no code tags

===============

is a dumb and inferior substitute
 
Old 11-28-2013, 09:16 AM   #33
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
no code tags

===============

is a dumb and inferior substitute
I am not understand the meaning , you mean change === to ---- ?
I have done it
 
Old 11-28-2013, 02:07 PM   #34
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
done what?

ahh, I see

you changed

==========
your code
==========
to
----------
your code
----------

which is still dumb,

I can/will not help you if you fail to follow simple instruction (post 26)

too late now , all too simple.. work it out yourself
 
Old 11-29-2013, 05:15 AM   #35
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As mentioned, please post code, data in code tags as per https://www.linuxquestions.org/quest...do=bbcode#code
 
Old 12-06-2013, 02:57 AM   #36
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Hi all ,

I think the below format is correct .

Code:
#!/bin/bash

MyString="abc\.)%@"

Total=0
GetData () {
AwkMyString="$( sed -e 's/[\/*?.+{}]/\\&/g' -e 's/[[]/\\&/g' -e 's/[]]/\\&/g' <<< "${MyString}" )"
for File in *.txt;do
Date="$(date "+%b %Y" --date="${File:4:6}01")"
awk 'BEGIN{C=0}{for (i=1;i<=NF;i++) if ( $i ~ /'${AwkMyString}'/ ){C++}} END{printf "%s %s?","'"${Date}"'",C}' "$File"
done
}
while read -d '?' Month Year Count;do
TableDate+=("${Month} ${Year}")
TableCount+=("${Count}")
done <<< $(GetData)

printf "%10s" "|"
for i in $(seq 0 $(( ${#TableDate[@]} - 1 )) );do
printf "%s |" "${TableDate[$i]}"
done
printf " Total |\n"


for i in $(seq 0 $(( ${#TableCount[@]} +1 )) );do
printf "=========|"
done
printf "\n"
printf "%10s" "|"
for i in $(seq 0 $(( ${#TableCount[@]} - 1 )) );do
printf "%*s%*s" $(( $((11 + ${#TableCount[$i]}))/2 )) "${TableCount[$i]}" $(( $((10 - ${#TableCount[$i]}))/2 )) "|"
done
for i in $(seq 0 $(( ${#TableCount[@]} - 1 )) );do
Total=$(( ${TableCount[$i]} + ${Total} ))
done
printf "%*s%*s" $(( (11 + ${#Total})/2 )) "${Total}" $(( (10 - ${#Total})/2 )) "|"
My current problem is when run the above script , I got the result as below , the heading is duplicated , I tried many modification but still not work , would you help to fix it ? thanks

|Oct 2013 | Total |
=========|=========|=========|
| 14 | 14 | |Oct 2013 |Oct 2013 | Total |
=========|=========|=========|=========|
| 14 | 14 | 28

Last edited by byran cheung; 12-06-2013 at 03:12 AM.
 
Old 12-08-2013, 07:26 PM   #37
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Original Poster
Rep: Reputation: Disabled
Hi ,

I tried to remark each for loop to test it , but still not work .

I think the script is nearly complete , would you please help for it , very thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find largest number in file? qrange Linux - Newbie 5 04-09-2012 06:39 AM
How to find which file has a string when large number of files dwynter Linux - Newbie 2 09-10-2008 06:06 AM
Find Number of column in a file Swapna173 Linux - Newbie 3 06-04-2008 01:29 AM
How can I find the AG number of a certain file?(XFS) hxsrmeng Linux - Newbie 0 09-14-2007 12:21 PM
How to find out the number of open file descriptors? skie_knite007 Programming 2 12-11-2005 10:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration