vlad


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting vlad
# 1  
Old 10-01-2007
vlad

Hi people

I am trainee at a new job which requires me to use UNIX, am more than comfortable dealing with processes and so on, problem I am having is that files get to big 1000s of lines, and I am trying to number these lines using a script so I can deal with these files without losing track of which lines am looking at, problem is I cant get the number to go in front of the lines.

For example assume the file has the contents as follows:
Line of text One
Line of text Two
Line of text Three
Line of text Four

I want it to look like this
1)Line of text One
2)Line of text Two
3)Line of text Three
4)Line of text Four

But what I keep getting is
1)
2)
3)
4)
Line of text One
Line of text Two
Line of text Three
Line of text Four

My employer doesn’t want me using SED or AWK Smilie, which is a shame because I got it to work easy with either of them.
Also temp variables wont do as the system is restarted every 2hrs, and the process am trying to achieve has to be automated.

Any tips or suggestions will greatly appreciated.

thanks
# 2  
Old 10-01-2007
Since you are viewing the files, why dont you the 'set number' feature in vim.

:set number to be more precise.
# 3  
Old 10-01-2007
thanks you the quick reply

i dont want to just view the files, i want to edit them using a simple shell script, nothing to fancy.

i dont really know what :set number is :P, i shall look into it.

thanks again
# 4  
Old 10-01-2007
if editing the files is that way is not possible i can save them to new files with that numbered format, i.e read the input of a file and copy to a new.
# 5  
Old 10-01-2007
firstly, show your code

secondly:
Quote:
Originally Posted by barbus

My employer doesn't want me using SED or AWK :
thanks
does your employer know any unix? If they know, then they should know sed/awk are essential tools that most admins use.
not tested,
Code:
v=0
while read  line
do
 v=$((v+1))
 printf "%s) %s\n"  $v  $line 
done < "file"

# 6  
Old 10-01-2007
I dont get exactly what you are trying to say. But perhaps this may help.
Code:
nl file.txt > file_with_numbered_lines.txt

Also, if you have set nu, in your .vimrc, then all the lines will be numbered when you open the file. You can do editing as well.
# 7  
Old 10-01-2007
Assume xx is the file with the relevant contents.
#!/bin/bash
Lines = wc-l << xx /* the number of lines from the file */
Number=0
while (($Number > $lines+1))
do
Number=$(($Number+1))
echo "$Number” /*at this point how do I call the text on that line number*/

/*then output to any new file (not important at this point)*/

done

This is the type of mini programme am trying to create, perhaps I am way over my head with this, but hey learning is a process Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question