numbering lines according to a condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting numbering lines according to a condition
# 1  
Old 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 Smilie

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 Smilie

#!/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
# 2  
Old 01-26-2009
Quote:
Originally Posted by elionba82
I'd like not to use awk o sed...that's why I found them tooooo difficult Smilie
And what is the reason to make it so difficult? Is it a homework assignment?

Regards
# 3  
Old 01-26-2009
no thankfully I don't study anymore...I do by myself, probably I'm not so good as you Smilie if you give me help with that commands for sure I can't handle them...
thanks anyway
# 4  
Old 01-26-2009
I succedeed in creating this script...if anyone needs it please ask me...

Last edited by elionba82; 01-26-2009 at 10:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep certain lines with condition

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

2. Shell Programming and Scripting

remove duplicate lines with condition

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

3. UNIX for Dummies Questions & Answers

numbering lines in a file

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

4. Shell Programming and Scripting

Numbering file's lines

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

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

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

6. Shell Programming and Scripting

Removing lines with condition

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

7. UNIX for Dummies Questions & Answers

Numbering lines grep

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

8. Shell Programming and Scripting

Numbering Lines

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

9. Windows & DOS: Issues & Discussions

Numbering lines in a file

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

10. Shell Programming and Scripting

Numbering lines in a file

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
Login or Register to Ask a Question