Visit Our UNIX and Linux User Community


vlad


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting vlad
# 8  
Old 10-01-2007
Quote:
Originally Posted by ghostdog74
Code:
v=0
while read  line
do
 v=$((v+1))
 printf "%s) %s\n"  $v  $line 
done < "file"


This is looks like something I can Smilie

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 :P

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 Smilie

Last edited by barbus; 10-01-2007 at 09:19 AM..
# 9  
Old 10-01-2007
Trying out grep and am confused as hell
I am using $user to save time.
Is this a valid method? xx is the file with contents

Code:
grep –i xx $user

So form what am reading I need to use pipes (new to me)

Code:
grep –n xx

will display the line numbers?

And
Code:
grep –I $user

should check for the current username in the file.

Do I need an other grep command to start from from line 1?

So I can use an if statement to check if the users is in the file, if so do the following:

Code:
 grep –n xx | grep –I $user | grep '^1' | >> newfile


Any feedback would be great ^^
# 10  
Old 10-01-2007
Quote:
Originally Posted by barbus
My employer doesn’t want me using SED or AWK.
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.
Change employer, he sounds like a teacher by giving you arbitary restrictions.
# 11  
Old 10-01-2007
if it was only that simple porter Smilie

if am not using SED or Awk, i have no idea what am doing in these situations.
# 12  
Old 10-01-2007
Quote:
Originally Posted by barbus
if am not using SED or Awk, i have no idea what am doing in these situations.
Perl, C, C++, Python, Pascal, Fortran, Java, ....

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.
# 13  
Old 10-01-2007
ok i am using this now, it works fine, but all i need to do is restrict the lines shown by a user, so am trying it with $USER for now.

#!/bin/bash/

x=0
while read line
do
x=$((x+1))
echo "$x ) $line"
done < "xx"

thx ghostdog74 Smilie
# 14  
Old 10-01-2007
Bug

thanks everyone for your help it works like a charm now. Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #88
Difficulty: Easy
PowerShell makes use of pipes.
True or False?

Featured Tech Videos