Shell script to print date and no.of records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to print date and no.of records
# 1  
Old 12-09-2012
Shell script to print date and no.of records

hi all,
i want script to print the output in the following format

filename yyyy/mm/dd count

where count= no.of records in the file

Thanks in advance
hemanthsaikumar
# 2  
Old 12-09-2012
Code:
for file in *
do
  count=$(wc -l < $file)
  echo $file `date +%Y/%m/%d` $count
done

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 12-09-2012
hey thankyou very much for your help
one more doubt
i want to restrict the filename to 30 bytes.. that means if the file name is 20 bytes it should print the 30 byte name by taking the space as input

Thanks in advance
saikumar
# 4  
Old 12-10-2012
Quote:
Originally Posted by hemanthsaikumar
hey thankyou very much for your help
one more doubt
i want to restrict the filename to 30 bytes.. that means if the file name is 20 bytes it should print the 30 byte name by taking the space as input

Thanks in advance
saikumar
Code:
for file in *
do
  count=$(wc -l < $file)
  #echo $file `date +%Y/%m/%d` $count
   printf "%-30s %10s %5d\n " $file `date +%Y/%m/%d` $count
done

# 5  
Old 12-10-2012
if the file name length is less than 30 bytes the spaces are getting appended...
what if the file name is greater than 30 bytes....?
for the above code it is not getting trimmed to 30 bytes....

thanks in advance
saikumar.
# 6  
Old 12-10-2012
Quote:
Originally Posted by hemanthsaikumar
if the file name length is less than 30 bytes the spaces are getting appended...
what if the file name is greater than 30 bytes....?
for the above code it is not getting trimmed to 30 bytes....

thanks in advance
saikumar.
Code:
for file in *
do
  COUNT=$(wc -l < $file)
  DATE=$(date +%Y/%m/%d)
  file=${file:0:30}
  #echo $file `date +%Y/%m/%d` $count
   printf "%-30s %10s %5d\n " $file $DATE $COUNT
done

# 7  
Old 12-10-2012
could you please explain what is
file=${file:0:30}
%-30s %10s %5d\n
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies

2. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

3. Shell Programming and Scripting

Delete db records from shell script

Hello Mates, I would request your help in a shell script, simply I need to delete some matching db table records (rows) to ones in a given file: ------------------------------ #!/bin/bash SQL="delete from numberlist where msidn='';" MYSQL_USER="<your-user>"... (4 Replies)
Discussion started by: EAGL€
4 Replies

4. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

5. Shell Programming and Scripting

Shell script matching similar records

hello all, I have requirement to identify similar records matching about 80% to 90%.I have to black list customers with multiple accounts. The data is in the Oracle Database, but is there any way I can get the data into flat file and compare the strings and fetch similar matching records? ... (2 Replies)
Discussion started by: kashik786
2 Replies

6. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

7. Shell Programming and Scripting

Help with shell script in formatting the records.

I have a text file in the following format. can any one please help me in printing the output in userfriendly format mentioned below. Input. 1) /ss/abc/1/w/s/domainname/abc1/logname/ ########error################### ########error################### ########error###################... (2 Replies)
Discussion started by: vinny81
2 Replies

8. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

9. Shell Programming and Scripting

need shell script to read particular records from a file

i am reading an i/p file input.txt as below and want to read all filenames as in highlighted in bold below and put them in a different file output.txt. can someone help me with a shell script to do this? thanks in advance regards brad input.txt --------- START TYPE:OPT INIT_SEQ:01... (8 Replies)
Discussion started by: bradc
8 Replies

10. UNIX for Dummies Questions & Answers

update records in a file using shell script...

Hi, I have a file with 6 columns. First 3 columns together make unique record. I have a variable ($v) which hold a value that is obtained by a caliculaion. I have to replace value in 5th columnn with the value of the variable ($v). The value $v is caliculated from col4 and col6 values. ... (2 Replies)
Discussion started by: new_learner
2 Replies
Login or Register to Ask a Question