displaying/ counting lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting displaying/ counting lines
# 1  
Old 08-07-2007
displaying/ counting lines

I have a file called xx with the env redirected into it 5 times:
env >> xx
env >> xx
env >> xx
env >> xx
env >> xx
I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that line and append it to a file and display a line number and a bracket against the saved line. The file should look lie that:
1) PWD=...
2) USER=...
3) MAIL=...
4) LOGNAME=...
5) HOME=...
6) PWD=...
7) USER=...
8) MAIL=...
9) LOGNAME=l...
10) HOME=...
I can not use temporary file, sed, awk...

Can somebody help meSmilie

So far I' ve got something like this:

echo "Give the name of the file: "
read fileName
egrep -w "PWD" $fileName | cat -b >> $fileName
egrep -w "USER" $fileName | cat -b >> $fileName
egrep -w "MAIL" $fileName | cat -b >> $fileName
egrep -w "LOGNAME" $fileName | cat -b >> $fileName
egrep -w "HOME" $fileName | cat -b >> $fileName
# 2  
Old 08-07-2007
Aga, you are breaking the rules with duplicate posting:
displaying/ counting lines

Also, this seems like homework.
# 3  
Old 08-08-2007
grep -c counts

read the man pages
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Displaying all the lines starting with some keyword

consider the contents of a file has many stuff including few stuff that i need.. so i perfromed the below function cat filename | grep "ALTER TABLE" its output is as shown below . . . . . SET @sql:=CONCAT('ALTER TABLE RecordMixProfile AUTO_INCREMENT=', @maxId) ; SET... (14 Replies)
Discussion started by: vivek d r
14 Replies

2. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

3. Shell Programming and Scripting

displaying multiple lines using AWk

say I'm doing awk 'NR==534' Is there a way to display 534 535 536 537? without appending to a variable? per line? maybe an easier way with a different command? My first impression was NR==534-537 but that would be too easy :P (2 Replies)
Discussion started by: puttster
2 Replies

4. Shell Programming and Scripting

Displaying lines of a file which have the highest number?

Hello Wondering if anybody may be able to advise on how I can filter the contents of the following file: <object_name>-<version> <Instance> GM_GUI_code.fmb-4 1 GM_GUI_code.fmb-5 1 GM_GUI_code.fmx-4 ... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

5. Homework & Coursework Questions

Displaying specific lines from a CSV file

1. The problem statement, all variables and given/known data: Display from a csv file, birthdays that occur today. If there are no birthdays today, the next one in the year. 2. Relevant commands, code, scripts, algorithms: The csv file is ordered from older to younger (ie. the most recent... (8 Replies)
Discussion started by: Adzi
8 Replies

6. Shell Programming and Scripting

counting the number of lines - again

Hi all, I use bash shell and I have a problem with wc. I would like to determine the number of lines in a file so I do wc -l filename but I don't want to get the filename again I just would like to have the number of lines and use it in a variable. Can anybody help? Thank you, (7 Replies)
Discussion started by: f_o_555
7 Replies

7. Shell Programming and Scripting

Displaying number of lines from file

Hi, I am using below command to display the number of line, but its returning no of lines along with file name. But i want only no of line in the variable p. Please help me on this? p=`wc -l "text file"` echo "$p" (6 Replies)
Discussion started by: shivanete
6 Replies

8. UNIX for Dummies Questions & Answers

Displaying specific lines in a file.

I'm trying to figure out how to display a certain line in a text file. I keep getting references to Tail and Head, and I know how these work, but i'm lost on how to find say the third out of the five lines and display only that. I thought maybe grep could help, but that doesn't seem likely. ... (3 Replies)
Discussion started by: MaestroRage
3 Replies

9. UNIX for Dummies Questions & Answers

displaying/ counting lines

I have a file called xx with the env redirected into it 5 times: env >> xx env >> xx env >> xx env >> xx env >> xx I have to read an input file (here: xx) and look for occurrences of the current user who is executing this script. Once finding an occurrence of the username I have to take that... (4 Replies)
Discussion started by: aga
4 Replies

10. UNIX for Dummies Questions & Answers

help with displaying certain lines

suppose i have a file which contains this: 00 07 * * * /home/production/bin/xxx.ksh 00 08 * * * /home/production/bin/xyz.ksh 00 12 * * * /home/production/bin/tuv.ksh 30 06 * * * /home/production/bin/cde.ksh 30 10 * * * /home/production/bin/put.ksh 00 01 * * * /home/production/bin/lik.sh ... (3 Replies)
Discussion started by: rooh
3 Replies
Login or Register to Ask a Question