Counting lines and files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Counting lines and files
# 1  
Old 12-11-2003
Question Counting lines and files

Hi experts,

First of all thanks for all your help.
How can i count the lines within a text file and send this number to another text file?
And by the way how can i count the number of files inside a tape ("/dev/rtp") that as one pattern (Ex. "/CTA/") and send this number to a text file?
I don't even know where to start,

Can someone help?

Thank you,

Jorge Ferreira
# 2  
Old 12-11-2003
Hi,

Counting lines inside a file and counting lines inside a file on tape are two different thing.

First of all, if you have a plain text-file you can do this using "wc -l"

F.E. : cat /var/adm/messages | wc -l >>/tmp/lines

This will count the number of lines from de messages file and <strong>appends</strong> this number to the file /tmp/lines

looking on tape depends on how you saved it. "tar tvf /dev/rtp", might tell you the files that are on the tape, but no garantuee. fining out the number of lines per file can only be done when restoring the file. At least for as far as I know. Maybe we can help a little more on this if we get to know the backup tool and method.

Regs David
# 3  
Old 12-11-2003
The Backup tool

The Backup tool is also a script.

This Script is this:



cd /
lincacd

cd /home/jorge/JJ
rm ./log.txt

date "+Backup started at %d/%m/%Y - %T" >> ./log.txt

#Backup integral
cd /usr/acct/sigma/disam
tar cvf /dev/rtp ./CTA/dados ./CTA/dados.2002 ./CTA/dados.2004 ./ARM/dados ./ARM/dados.2002 ./PAT/dados ./CEM ./CIC ./FEI ./UPA ./PUB ./GERAIS ./GERAIS.2002

cd /home/jorge/JJ
date "+Backup ended at %d/%m/%Y - %T" >> ./log.txt

exit



Where ./CTA, ./ARM ... are different directories. After this script, i would like to know how many files have been copied to the tape (/dev/rtp) from each one of these directories.

As you can see, right now the only information it gives me is when it has started and ended. What i want is to know how many files did it copied in each directory. That's why i wanted to know how could i get the number of files within a tape that followed some pattern ("./CTA"). Can 'grep' do this?

Thank you for your reply
# 4  
Old 12-11-2003
Hi,

Looking at your script we can find out you use tar. Unfortunetly I do not know the device /dev/rpt However, I think you can do a "mt rewind" and then a "tar tvf /dev/rpt | wc -l"

If you do not trust the output you could also do a "tar tvf /dev/rpt" without the wc -l. Just as a test.

Regs David
# 5  
Old 12-11-2003
MySQL Almost done

Hello David,

I've got it, but only with your help.
If i do 'tar tvf /dev/rtp grep -l ./CTA |wc -l', i can see how many files i've got inside './CTA' directory. The only thing i need to do is to send this number to the log.txt file.
The command 'tar tvf /dev/rtp grep -l ./CTA |wc -l >> log.txt' would do the trick but i need to send also text before, so it say for example: 'Number of records inside CTA --> 700' where 700 is what '|wc -l' returns.

This would be probably the easy part for you but ...

Thanx again
# 6  
Old 12-11-2003
Hi,

I think you need a little more than just a line.

var=`tar tvf /dev/rtp grep -l ./CTA |wc -l`
echo 'Number of records inside CTA --> $var'

On it's trun you can redirect this again to /tmp/file or send it by e-mail, etc.
Note that the var= continues with a backtick ` This starts it as a command in a new shell.

Regs David
# 7  
Old 12-11-2003
All done

Well,

Thank you very much my dear friend.
If there's any other problem around here, people can use this solution because it works.

Thank you David.

Best Regards,
Jorge Ferreira
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

2. Shell Programming and Scripting

sed counting lines

Hi, I'm using the command: sed -n '$=' $1 on a sh script on AIX. This script is used to count the number of lines of files. If the file has no lines at all the command doesn't return nothing. I need the command to return 0 when the file has no lines at all. How can I achieve this? Best... (5 Replies)
Discussion started by: jppedroso
5 Replies

3. UNIX for Advanced & Expert Users

Delete # of Lines after counting

I'm trying to write a script to clean up log file automatically when it reaches 1000 lines. I can't get this to work..can some help me please :) Server: SunOS 5.8 Generic_117350-53 sun4u sparc SUNW,Netra-T12 #!/bin/ksh #file reference file=`echo "$HOME/support/moe/b.tc"` #linecount... (7 Replies)
Discussion started by: moe458
7 Replies

4. Shell Programming and Scripting

Counting lines for each application

Hi All, I have a output that suppose to be like this (see below please) App : Line counts === ================== AAA: 100 BBB: 201 CCC: 137 DDD: 32 EEE: 55 for i in `ps -ef | grep App`; do print $i; done This only shows App : === (12 Replies)
Discussion started by: Beginer0705
12 Replies

5. Shell Programming and Scripting

Counting similar lines

Hi, I have a little problem with counting lines. I know similar topics from this forum, but they don't resolve my problem. I have file with lines like this: 2009-05-25 16:55:32,143 some text some regular expressions ect. 2009-05-25 16:55:32,144 some text. 2009-05-28 18:15:12,148 some... (4 Replies)
Discussion started by: marcinnnn
4 Replies

6. Shell Programming and Scripting

Counting lines between two patterns

Hi Guys, I have a file as follows: wwe khfgv jfo wwe jhgfd wwe wwe hoaha hao lkahe wwe (13 Replies)
Discussion started by: npatwardhan
13 Replies

7. Shell Programming and Scripting

Counting lines in multiple files

Hi, I have couple of .txt files (say 50 files) in a folder. For each file: I need to get the number of lines in each file and then that count -1 (I wanted to exclude the header. Then sum the counts of all files and output the total sum. Is there an efficient way to do this using shell... (7 Replies)
Discussion started by: Lucky Ali
7 Replies

8. Shell Programming and Scripting

counting the lines of diff files in loop

i have two file. i want to count the lines of each file one by one in loop and compare it. can any one pls help me on this? (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

9. Shell Programming and Scripting

Merging files with AWK filtering and counting lines

Hi there, I have a couple of files I need to merge. I can do a simple merge by concatenating them into one larger file. But then I need to filter the file to get a desired result. The output looks like this: TRNH 0000000010941 ORDH OADR OADR ORDL ENDT 1116399 000000003... (2 Replies)
Discussion started by: Meert
2 Replies

10. Linux

counting the number of lines

Hello, I have afile which begins with a few urls on multiple lines and then there is listing of some information on separate lines. The listing begins with the word Name on a given line followed by teh actual list. I want to count the number of lines in this file after the line having... (6 Replies)
Discussion started by: nayeemmz
6 Replies
Login or Register to Ask a Question