473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Another Unix Question

keyvanrahmadi
I have file which has been created as follow:

Expand|Select|Wrap|Line Numbers
  1. env >>  XX
  2. env >>  XX
  3. env >>  XX
  4. env >>  XX
  5. env >>  XX
  6.  
The purpose of the task is to create a script which will find all the occurrences of the username and append it to a file and display a line number and a bracket against the saved line. Since i am not allowed to use SED or AWK i have come up with the follwoing script.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/bin/bash
  3.  
  4. grep  keyvan.ahmadi XX  > exp | sort exp | uniq > exp1
  5.  
  6. echo " Script Created"
  7.  
  8.  
The problem i have is, i dont have a clue how to display teh line number and brackets. Any help would be great


Thx in advance

Keyvan
Apr 16 '07 #1
5 1428
ghostdog74
511 Expert 256MB
i won't do your homework for you, but i give you hints. since you can't ues sed, awk, you have to use in built functions of bash and loops as well.
you can set a loop to go thorugh the file, at the same time initialize a counter so that as you go through each line , you print the counter, after that, increment the counter.
something like that.
Apr 17 '07 #2
i won't do your homework for you, but i give you hints. since you can't ues sed, awk, you have to use in built functions of bash and loops as well.
you can set a loop to go thorugh the file, at the same time initialize a counter so that as you go through each line , you print the counter, after that, increment the counter.
something like that.
tbh i really wouldnt want any one doing mt course work, otherwise i wont learn anything so there is no point learning. Your Hint got me tinking, i think i play around with a while loop. I look at the syntex when i get home.

thx well in advance mate

keyvan
Apr 17 '07 #3
ghostdog74
511 Expert 256MB
another hint: you can use cat to show the line number. check the man page of cat. it will show you the option you can use.
Apr 17 '07 #4
another hint: you can use cat to show the line number. check the man page of cat. it will show you the option you can use.
yes you mean cat -n file. my script is suppose to number and bracet them. The main problem is that i cant use temp files either, which puts the downer on what i have.

Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2. clear
  3. grep  keyvan.ahmadi XX  > exp | sort exp | uniq > xx-sorted
  4. echo " Script Created"
  5. rm exp
  6.  
i thought a while loop might do the trick, and read up on it, but tbh i am actually confused now and lost for words, and dont know what to do.
Apr 17 '07 #5
ghostdog74
511 Expert 256MB
check here for information. especially Part 3.
Apr 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jonathan Li | last post by:
I have posted the question before but nobody have given me a solution. I would like to rephrase my requirement and want to hear your advice. We are developing application packages for logistics...
5
by: jrefactors | last post by:
when people say unix programmer, does it mean they write programs in unix environment,and those programs are run in unix platform? it is not necessary they are using unix function calls? I heard...
6
by: john_williams_800 | last post by:
Hi; I am writing an html page that will live on one server in an ms windows network, but access pictures from a directory on another ms windows server in the network. I know in html the...
48
by: Daniel Rudy | last post by:
Hello, On a x86 machine, what is the format of a pointer in C? I know for a fact that the x86 p-mode uses a /selector:offset/ notation where the selector is defined in either the GDT or LDT. ...
5
by: markus | last post by:
Hi, I have a question that deals with the standard c library VS (Unix) system calls. The question is: which header files (and functions) are part of the C library and which header files (and...
46
by: dawn | last post by:
Hi all, I am now working on a C program under Unix. The requirement for the program is that: A file name is passed to program as a parameter. The program will Find files under a specified...
39
by: anonymous | last post by:
Dear All, >From my understanding of pointers, a pointer should not be able to access a memory location until that memory has been allocated either by assiging the address of a variable or...
24
by: David Mathog | last post by:
On a Solaris 8 system if a user "joe" logs in, for instance via ssh, cuserid() returns "joe". That's the expected behavior and so far so good. However if that user then does: % su - sally ...
1
by: Marcin Wiszowaty | last post by:
Hello, I work at a company that has 2 development enviroments. One Unix which i dont know anything about and the othe vs.net 03 with MSSQL server 2000 for db. How can i cause applications...
5
by: Mirxon | last post by:
Hello, I'm working on a C program under Ubuntu. It's basd on socket. Browser calls a client cgi (C program), and send some parameters to server (C program). Server runs another program...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.