I have been trying to write the same logic in a different way:
i.e. Instead of loading the file into an array (memory), I would like to read the file line by line and then check for the conditions:
The code looks lile:
Here:
The script runs perfectly. It actually read line by line and then check for conditions.
But,
The header contains 107 lines i.e.
Since its 107 lines, while I am counting the number of lines its calculating the entire number of lines including the header and then doing the grep and substituting but instead it should exclude the header and do the remaining.
Other than that The footer looks good.
Could you please tell me whether is there any way to that after inserting the good lines into an array, calculating the number of lines without the header ?
I would like to remove some lines from begining of file (header) and some lines from end of file (footer).
The header/footer lines generated by web-browser when the user upload a file to my webserver.
Example:
-----------------------------7d62af20c052c
Content-Disposition: form-data;... (2 Replies)
Hi Gurus,
My requirement is, I am passing a file1.dat into this(rowcnt.sh) script,but returning a wrong value of -2.(it should be 4).Becoz my file1.dat contains 6records incl: Header & Footer.(6-2=4)
wrong output:
-------
#sh rowcnt.sh file1.dat
-2 actual_cnt except HDR & FTR
should be:... (3 Replies)
Hi All,
I have several txt files i need to enter specific header and footer (both are separate) to all these files how can i do this? plz help..
Regards,
Raghav (4 Replies)
Hi, Guys,
I want add header and footer in a file. I can add footer using following command:
echo "Footer" >>file.
I don't know how to add header.
Thanks in advance (4 Replies)
Hi,
I need to check whether the incoming file has a header and footer using a UNIX script. The pattern of the header and footer is fixed as follows:
Header: Name,Date
Footer: Count, Total
Name,Date
-------------------------
-------------------------
-------------------------
Count,... (5 Replies)
Hi,
TASK 1:
I have been using this code to print the information of files kept at "/castor/cern.ch/user/s/sudha/forPooja" in some text file name FILE.txt.
rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > FILE.txt
... (6 Replies)
Hi All,
I need to write a script that In my file I have to check header and footer records are available or not. If it is available I have to run the script, otherwise I should not. But current script it is checking only the data inside the script. It is avoiding to check Header and Footer... (1 Reply)
I have two files which are getting sent to a UNIX server in order to be bcp'd into a database. The bcp is failing because there's a header and footer row on the file which give the date of the file and the number of rows in it. That's because the file is also being used for another process, so we... (1 Reply)
This is my file(Target.txt)
name|age|locaction
abc|23|del
xyz|24|mum
jkl|25|kol
The file should be like this
1|03252012
1|name|age|location
2|abc|23|del
2|xyz|24|mum
2|jkl|25|kol
2|kkk|26|hyd
3|4
Column 1 is row indicator
for row 1 and 2, column indicator is 1,for data rows... (1 Reply)
Hi I have below requirements on the script below :
(1) I receive 2 pipe seperated file called OUT.psv and DIFF.psv with a column header.I concatenate the 2 files and create a final.psv file. I want to add another header as START_FILE to the final.psv file . How to achieve this ?
(2) I have... (5 Replies)
Discussion started by: samrat dutta
5 Replies
LEARN ABOUT OSX
nl
NL(1) BSD General Commands Manual NL(1)NAME
nl -- line numbering filter
SYNOPSIS
nl [-p] [-b type] [-d delim] [-f type] [-h type] [-i incr] [-l num] [-n format] [-s sep] [-v startnum] [-w width] [file]
DESCRIPTION
The nl utility reads lines from the named file or the standard input if the file argument is ommitted, applies a configurable line numbering
filter operation and writes the result to the standard output.
The nl utility treats the text it reads in terms of logical pages. Unless specified otherwise, line numbering is reset at the start of each
logical page. A logical page consists of a header, a body and a footer section; empty sections are valid. Different line numbering options
are independently available for header, body and footer sections.
The starts of logical page sections are signalled by input lines containing nothing but one of the following sequences of delimiter charac-
ters:
Line Start of
::: header
:: body
: footer
If the input does not contain any logical page section signalling directives, the text being read is assumed to consist of a single logical
page body.
The following options are available:
-b type Specify the logical page body lines to be numbered. Recognized type arguments are:
a Number all lines.
t Number only non-empty lines.
n No line numbering.
pexpr Number only those lines that contain the basic regular expression specified by expr.
The default type for logical page body lines is t.
-d delim Specify the delimiter characters used to indicate the start of a logical page section in the input file. At most two characters
may be specified; if only one character is specified, the first character is replaced and the second character remains
unchanged. The default delim characters are ``:''.
-f type Specify the same as -b type except for logical page footer lines. The default type for logical page footer lines is n.
-h type Specify the same as -b type except for logical page header lines. The default type for logical page header lines is n.
-i incr Specify the increment value used to number logical page lines. The default incr value is 1.
-l num If numbering of all lines is specified for the current logical section using the corresponding -b a, -f a or -h a option, spec-
ify the number of adjacent blank lines to be considered as one. For example, -l 2 results in only the second adjacent blank
line being numbered. The default num value is 1.
-n format Specify the line numbering output format. Recognized format arguments are:
ln Left justified.
rn Right justified, leading zeros suppressed.
rz Right justified, leading zeros kept.
The default format is rn.
-p Specify that line numbering should not be restarted at logical page delimiters.
-s sep Specify the characters used in separating the line number and the corresponding text line. The default sep setting is a single
tab character.
-v startnum Specify the initial value used to number logical page lines; see also the description of the -p option. The default startnum
value is 1.
-w width Specify the number of characters to be occupied by the line number; in case the width is insufficient to hold the line number,
it will be truncated to its width least significant digits. The default width is 6.
ENVIRONMENT
The LANG, LC_ALL, LC_CTYPE and LC_COLLATE environment variables affect the execution of nl as described in environ(7).
EXIT STATUS
The nl utility exits 0 on success, and >0 if an error occurs.
SEE ALSO jot(1), pr(1)STANDARDS
The nl utility conforms to IEEE Std 1003.1-2001 (``POSIX.1'').
HISTORY
The nl utility first appeared in AT&T System V Release 2 UNIX.
BUGS
Input lines are limited to LINE_MAX (2048) bytes in length.
BSD January 26, 2005 BSD