Sponsored Content
Top Forums UNIX for Advanced & Expert Users Delete # of Lines after counting Post 302466470 by ctsgnb on Tuesday 26th of October 2010 12:17:10 PM
Old 10-26-2010
1. You are true, i fixed my code with the if then instead of &&.

2. My turn now... Smilie ... WARNING about your code :

a) if [ `wc -l $file` ] : this doesn't check whether is exceed 1000 lines

b) by using mv log.tmp $file, you will loose the inode of $file !!!!

this mean that if the logfile is currently being processed you may encounter unexpected behaviour or errors.
That is the reason why it is advisable to use
Code:
cat log.tmp >$file 
rm log.tmp

instead of mv log.tmp $file

Quote:
Originally Posted by rbatte1
I'm not sure of your syntax here. We have an if without a then but using && instead and I'm not sure what else will get processed. You may just career on into the cat log.tmp>$file hence why the failure at the else statement.

Consider this:-
Code:
if [ `wc -l $file` ]
then
   tail +101 $file > log.tmp
   mv log.tmp $file
else
   echo "Line count of $file is `wc -l $file`"
fi

I hope that this helps.
Robin

Last edited by ctsgnb; 10-26-2010 at 02:00 PM..
These 2 Users Gave Thanks to ctsgnb For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

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... (6 Replies)
Discussion started by: jorge.ferreira
6 Replies

2. 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

3. UNIX for Dummies Questions & Answers

displaying/ counting lines

I have a file called xx with the env redirected into it 5 times: env >> xx env >> xx env >> xx env >> xx env >> xx I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that... (4 Replies)
Discussion started by: aga
4 Replies

4. Shell Programming and Scripting

displaying/ counting lines

I have a file called xx with the env redirected into it 5 times: env >> xx env >> xx env >> xx env >> xx env >> xx I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that... (2 Replies)
Discussion started by: aga
2 Replies

5. Shell Programming and Scripting

counting the number of lines - again

Hi all, I use bash shell and I have a problem with wc. I would like to determine the number of lines in a file so I do wc -l filename but I don't want to get the filename again I just would like to have the number of lines and use it in a variable. Can anybody help? Thank you, (7 Replies)
Discussion started by: f_o_555
7 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 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

8. 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

9. 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

10. 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
PCSC-SPY(1)							    PC/SC lite							       PCSC-SPY(1)

NAME
pcsc-spy - A PC/SC spy command SYNOPSIS
pcsc-spy [-n|--nocolor] [-d|--diffable] [-h|--help] [fifo_filename] DESCRIPTION
pcsc-spy displays PC/SC calls of an application. It must be used with the libpcscspy.so library. To be able to spy the PC/SC layer, the application flow must be modified so that all PC/SC calls are redirected. Two options are available: - the application is linked with libpcsclite.so.1 - the application loads the libpcsclite.so.1 library using dlopen(3) OPTIONS
-d, --diffable Demove the variable parts (like handler values) from the output so that two execution can be more easily compared. -h, --help Display a short help text. -n, --nocolor Disable the output colorization (if you want redirect the output in a file for example). -v, --version Print the version of the pcsc-spy program plus a copyright, a list of authors. EXAMPLES
Applications linked with libpcsclite.so.1 We will use the standard LD_PRELOAD loader option to load our spying library. Example: LD_PRELOAD=/usr/lib/libpcscspy.so opensc-tool -a Application loading libpcsclite.so.1 This is the case for the PC/SC wrappers like pyscard (for Python) and pcsc-perl (for Perl). The LD_PRELOAD mechanism can't be used. Instead we replace the libpcsclite.so.1 library by the spying one. You may use install_spy.sh and uninstall_spy.sh to install and uninstall the spying library. Using the spying library without pcsc-spy is not a problem but has side effects: - a line "libpcsclite_nospy.so.1: cannot open shared object file: No such file or directory" will be displayed - some CPU time will be lost because of the PC/SC calls redirection Starting the spy tool pcsc-spy If a command argument is passed we use it instead of the default ~/pcsc-spy FIFO file. It is then possible to record an execution log and use pcsc-spy multiple times on the same log. To create the log file just do: mkfifo ~/pcsc-spy cat ~/pcsc-spy > logfile and run your PC/SC application. Mac OS X The installation is not automatic. In the pcsc-lite/src/spy directory do: make framework Then copy the PCSC.framework directory in /tmp cp -a PCSC.framework /tmp Copy the official PCSC.framework (binary only) in /tmp cp /System/Library/Frameworks/PCSC.framework/PCSC /tmp Run the application to debug as: DYLD_FRAMEWORK_PATH=/tmp pcsctest FILES
~/pcsc-spy FIFO file is used by libpcsclite.so.1 to send the raw log lines SEE ALSO
pcscd(8) AUTHOR
This manual page was written by Ludovic Rousseau <rousseau@free.fr> pcsc-lite 1.8.4 2012-02-01 PCSC-SPY(1)
All times are GMT -4. The time now is 08:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy