01-26-2009
numbering lines according to a condition
hello again guys,
I tried to make a script but due to array's limitations I didn't succeed...so I'm asking you
I need numbering the lines according to date (everyday I need to restart the counter)
for example:
ABCBD 20080101 XXX 1
FSDFD 20080101 BBB 2
FSDFD 20080102 HHH 1
and so on...
I'd like not to use awk o sed...that's why I found them tooooo difficult
#!/bin/ksh93
file1='/spooldocs/1.txt'
file2='/spooldocs/2.txt'
n=1
cat "$file1" |
while read line
do
if [[ "line:8:8" == "line_old:8:8"]]
echo "$line $n" >> file2
n=n+1
$line=line_old
done
obviously it doesn't work (ok there are some errors 'cause trying i deleted the tested one...but i think the problem is in concept)
also i need not to change tabulation
thanks a lot
elio
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all,
I need to number the lines in a file.
I tried using "set nu" in the vi editor, but it is only temporary.
Can anyone help me please.
Thanx in advance.
MK (4 Replies)
Discussion started by: minazk
4 Replies
2. Windows & DOS: Issues & Discussions
Hi all,
I need to number the lines in a file.
I tried using "set nu" in the vi editor, but it is only temporary.
Can anyone help me please.
Thanx in advance.
MK (1 Reply)
Discussion started by: minazk
1 Replies
3. Shell Programming and Scripting
Hello everyone,
I want get numbered lines from a file. and i can do it with: sed = file.txt | sed "/./N; s/\n/ /" | sed -n "5,7p"
but the output that i get is something similar to:
5 line5
6 line6
7 line7
and i want something like this (with 2points after the number):
5:... (6 Replies)
Discussion started by: vibra
6 Replies
4. UNIX for Dummies Questions & Answers
Is there a way to number lines and use something other than ":" to separate the number from the line?
Or can anyone recommend a way to replace the ":" with a tab?
Here's what I'm working with:
16859:52.67
16860:46
16861:39.63
16862:33.88
16863:29.64
16864:26.27
16865:22.09... (1 Reply)
Discussion started by: jdolny
1 Replies
5. Shell Programming and Scripting
Hello guys,
I need help with a script for removing lines that does not satisfy a condition.
For example if a file has these lines:
aaaa bbbb cccc
aaaa bbbb cccc
dddd eeee ffff
gggg hhhh iiii
jjjj kkkk llll
aaaa bbbb cccc
jjjj kkkk lllll
dddd eeee ffff
dddd eeee ffff
Then I want... (4 Replies)
Discussion started by: jaysean
4 Replies
6. Shell Programming and Scripting
Hi,
my xml files looks something like this
<Instance Name="New York">
<Description></Description>
<Instance Name="A">
<Description></Description>
<PropertyValue Key="false" Name="Building A" />
</Instance>
<Instance Name="B">
... (4 Replies)
Discussion started by: tententen
4 Replies
7. Shell Programming and Scripting
hey
a file called test :
Code:
hey1
hey2
hey3
........
how to :
Code:
1.hey1
2.hey2
3.hey3
.......... (3 Replies)
Discussion started by: eawedat
3 Replies
8. UNIX for Dummies Questions & Answers
if we execute :set nu in vi mode, it displays the line numbers. so how to make this permanently in a file.
Whenever i execute cat , the line numbers should be there. please help me.
thanks (4 Replies)
Discussion started by: pandeesh
4 Replies
9. Shell Programming and Scripting
hi to all
Does anyone know if there's a way to remove duplicate lines which we consider the same only if they have the first and the second column the same?
For example I have :
us2333 bbb 5
us2333 bbb 3
us2333 bbb 2
and I want to get
us2333 bbb 10
The thing is I cannot... (2 Replies)
Discussion started by: vlm
2 Replies
10. UNIX for Dummies Questions & Answers
file input
aaaa,52C
aaaa,50C
bbbb,50C
bbbb,58C
aaaa,52C
bbbb,50C
aaaa,30C
bbbb,58C
cccc,60C
i want to print uniq lines with its max value of column2
expected output
aaaa,52C
bbbb,58C
cccc,60C
tks (4 Replies)
Discussion started by: radius
4 Replies
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 omitted, 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 signaled 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 signaling 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, specify the
number of adjacent blank lines to be considered as one. For example, -l 2 results in only the second adjacent blank line being num-
bered. 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.
EXIT STATUS
The nl utility exits 0 on success, and >0 if an error occurs.
SEE ALSO
pr(1)
STANDARDS
The nl utility conforms to X/Open Portability Guide Issue 4, Version 2 (``XPG4.2'') with the exception of not supporting the intermingling of
the file operand with the options, which the standard considers an obsolescent feature to be removed from a further issue.
HISTORY
The nl utility first appeared in AT&T System V Release 2 UNIX.
BSD
February 15, 1999 BSD