473,395 Members | 1,516 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,395 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 1430
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.