04-24-2018
It works for me, if the while loop reads from a text file.
What is pbpaste?
How does your input file look like? Is it Unix style? (where newline is LF, also the last line ends with LF, as opposed to DOS style where newline is CR LF and the last line has no newline)
10 More Discussions You Might Find Interesting
1. AIX
Hi,
I am new to AIX and I am developing a small tool for our product which helps debug memory leaks etc.
Q1)Is there a way in which i can get a function trace back as to the call (lets say malloc() )has been made in which file--> in which function.
I tried using the
#pragma options (... (0 Replies)
Discussion started by: Wkdunreal
0 Replies
2. Shell Programming and Scripting
I have this code, I thought it would automatically know the args sent to script when called from shell. But it seems to not see any...
main script:
. args
. errors
. opt
. clean
dbfile=""
opfile=""
# calls function in script below
chkarg
#check commands (2 Replies)
Discussion started by: gcampton
2 Replies
3. Homework & Coursework Questions
I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies
4. Shell Programming and Scripting
I need help with debugging an error in my awk script.
I have a shell script with variable named U_new_i and want to pass it to awk for use in a summation. The original file have the following content.
cat test.txt
-2445.7132000000
-2444.9349000000
-2444.3295000000
-2443.1814000000 ... (0 Replies)
Discussion started by: Quantum_Dot
0 Replies
5. Shell Programming and Scripting
I have a text file with file names, id like to have this portion of my BASH script go grab the line (which in this case is the full path to my file) then cat that file so I could pipe it to a email.
1) My text file (/tmp/1.txt) is setup like this:
... (3 Replies)
Discussion started by: binary-ninja
3 Replies
6. Programming
Here is the program I am trying to debug:
#include <stdio.h>
int i = 5;
int main(void)
{
int x = 3;
display(x);
return 0;
}
void display(int x)
{
for ( i=0; i<x; ++i ) {
printf("i is %d.\n", i);
}
}This code is coming from here Peter's gdb Tutorial: Stepping... (2 Replies)
Discussion started by: ijustneeda
2 Replies
7. Shell Programming and Scripting
I am new to shell scripting and wished to get few things clarified.
While calling functions within shell script, output comes out as single line irrespective of the no of echos or newlines I tried within function +
the echo -e used to invoke function ( as instructed online) :
#!/bin/sh
inc() {... (1 Reply)
Discussion started by: RMath
1 Replies
8. How to Post in the The UNIX and Linux Forums
I am using a grep command with two patterns in my KSH script. File has line breaks in it and both the patterns are in different lines. Here is the command - grep -l 'RITE AID.*ST.820' natriter820u.20140914
Pattern1 - RITE AID
Pattern2 - ST*820
I am not getting any results from this,... (3 Replies)
Discussion started by: Raghav Garg
3 Replies
9. UNIX for Dummies Questions & Answers
Hello
I am using a grep command with two patterns in my KSH script. File has line breaks in it and both the patterns are in different lines. Here is the command grep -l 'RITE AID.*ST.820' natriter820u.20140914
Pattern1 - RITE AID
Pattern2 - ST*820
I am not getting any results from... (24 Replies)
Discussion started by: Raghav Garg
24 Replies
10. UNIX for Beginners Questions & Answers
I am looking at a log file which just tells me the filename and the line number inside that file that has the Error. What I am interested is knowing the encapsulating function. For example, here are the contents of the log file
Error: foo.file on line wxy
Error: foo.file... (3 Replies)
Discussion started by: kaaliakahn
3 Replies
LEARN ABOUT DEBIAN
file::countlines
File::CountLines(3pm) User Contributed Perl Documentation File::CountLines(3pm)
NAME
File::CountLines - efficiently count the number of line breaks in a file.
SYNOPSIS
use File::CountLines qw(count_lines);
my $no_of_lines = count_lines('/etc/passwd');
# other uses
my $carriage_returns = count_lines(
'path/to/file.txt',
style => 'cr',
);
# possible styles are 'native' (the default), 'cr', 'lf'
DESCRIPTION
perlfaq5 answers the question on how to count the number of lines in a file. This module is a convenient wrapper around that method, with
additional options.
More specifically, it counts the number of line breaks rather than lines. On Unix systems nearlly all text files end with a newline (by
convention), so usually the number of lines and number of line breaks is equal.
Since different operating systems have different ideas of what a newline is, you can specifiy a "style" option, which can be one of the
following values:
"native"
This takes Perl's "
" as the line separator, which should be the right thing in most cases. See perlport for details. This is the
default.
"cr"
Take a carriage return as line separator (MacOS style)
"lf"
Take a line feed as line separator (Unix style)
"crlf"
Take a carriage return followed by a line feed as separator (Microsoft Windows style)
Alternatively you can specify an arbitrary separator like this:
my $lists = count_lines($file, separator => 'end{itemize}');
It is taken verbatim and searched for in the file.
The file is read in equally sized blocks. The size of the blocks can be supplied with the "blocksize" option. The default is 4096, and can
be changed by setting $File::CountLines::BlockSize.
Do not use a block size smaller than the length of the separator, that might produce wrong results. (In general there's no reason to chose
a smaller block size at all. Depending on your size a larger block size might speed up things a bit.)
Character Encodings
If you supply a separator yourself, it should not be a decoded string.
The file is read in binary mode, which implies that this module works fine for text files in ASCII-compatible encodings, including ASCII
itself, UTF-8 and all the ISO-8859-* encodings (aka Latin-1, Latin-2, ...).
Note that the multi byte encodings like UTF-32, UTF-16le, UTF-16be and UCS-2 encode a line feed character in a way that the 0x0A byte is a
substring of the encoded character, but if you search blindly for that byte you will get false positives. For example the LATIN CAPITAL
LETTER C WITH DOT ABOVE, U+010A has the byte sequence "0x0A 0x01" when encoded as UTF-16le, so it would be counted as a newline. Even
search for "0x0A 0x00" might give false positives.
So the summary is that for now you can't use this module in a meaningful way to count lines of text files in encodings that are not ASCII-
compatible. If there's demand for, I can implement that though.
Extending
You can add your own EOL styles by adding them to the %File::CountLines::StyleMap hash, with the name of the style as hash key and the
separator as the value.
AUTHOR
Moritz Lenz <http://perlgeek.de>, <mailto:moritz@faui2k3.org>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Moritz A. Lenz. This module is free software. You may use, redistribute and modify it under the same terms as perl
itself.
Example code included in this package may be used as if it were in the Public Domain.
DEVELOPMENT
You can obtain the latest development version from <http://github.com/moritz/File-CountLines>:
git clone git://github.com/moritz/File-CountLines.git
perl v5.10.1 2010-08-19 File::CountLines(3pm)