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 , 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.
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.
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
I have a question though, the �while read line� statement, how does this get information from the file, is it from this �done < "file"�?.
sorry if am asking silly questions i only been using UNIX for a week now
also can i use the grep to achieve this, if say i will be looking for occurrences of the current user who is executing the script?(in this case it should be me, but i can use it for others)
cat xx| grep -n .\*| grep "^1"
or something like that, i cant test it atm, but i think cat pipes file to 'grep -n' which inserts line numbers and pipes it to 'grep '^1' which gets the line 1. odds are this might fail as this is 1st time i am going to use grep
If an employer says write a UNIX script but don't use sed then that is called micro-managing. If a teacher says that it's because he wants you to grasp certain concepts.