How do I number my for loop outputs with this method?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I number my for loop outputs with this method?
# 1  
Old 08-02-2011
How do I number my for loop outputs with this method?

Currently I am outputting users and I want to number them starting with 1...

Code:
grep name list.txt | awk -F"=" '{ print $2 }' | while read user; do
        echo -e "1\t|$user"

Currently I have:
Code:
1   |  john
1   |  amy
1   |  max

I want it to look like
Code:
1   |  john
2   |  amy
3   |  max


Last edited by radoulov; 08-02-2011 at 11:56 AM.. Reason: Code tags.
# 2  
Old 08-02-2011
Try:


Code:
awk '/name/ {
  printf "%s\t|\t%s\n", ++c, $0
  }' infile

# 3  
Old 08-02-2011
Code:

awk -F"=" '/name/{ print ++cnt, $2 }' OFS='|' list.txt

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loop grep, outputs in files

Hi, I try to create a simply code but I have problems... Ubuntum, Bash version: 4.3.46 Bash INPUT file (csv): TS133_29BC,xx2274305 TS133_29BC,rps4576240 av137_37BC,wfs2274305 av137_37BC,ftrs4576240 T1S138_30BC,rfss2255526 T1S138_30BC,rgas2274305 OUTPUT files (csv): File TS133_29BC... (6 Replies)
Discussion started by: echo manolis
6 Replies

2. Shell Programming and Scripting

Challenge in finding listing class method and its number of code lines

there are about 300 objectivec .m files and I need to print each file name and its method and number of lines inside the method there is a sample perl files that do perl brace matching... (0 Replies)
Discussion started by: steve32001
0 Replies

3. Shell Programming and Scripting

Number loop

Hello, I've been trying to create a list of numbers in bash that loops every 10s as follow. So the list will contain 1-5 on start, then 2-6 after 10s and so on. However when it reaches 30 it needs to start back at 1. 1 2 3 27 28 2 3 4 28 29 3... (2 Replies)
Discussion started by: shadyuk
2 Replies

4. Shell Programming and Scripting

Compare two files, then outputs line number

I have two files, "ranked.txt" and "sorted.txt". Sorted.txt is a smaller subset from ranked.txt that is sorted in alpha order. However ranked.txt preserves the ranking of words I would like to keep. How do I check the rank of every word in sorted.txt when matched to the original ranked.txt? I... (8 Replies)
Discussion started by: pxalpine
8 Replies

5. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

6. Programming

infinite loop, synchronizing gossip-based method

the following code runs, but it hangs somewhere, i don't know why, #include<iostream> #include<vector> #include<cstdlib> #include<ctime> #include<list> #include<pthread.h> #include<cstring> using namespace std; pthread_mutex_t listlock = PTHREAD_MUTEX_INITIALIZER;... (3 Replies)
Discussion started by: saman_glorious
3 Replies

7. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

8. Shell Programming and Scripting

loop number of records.

Initially i store some files into anothe file Y. Now i want read the contents of file Y one by one do some check on each file. i,e Open file Y (contains multiple files) First read a file , do some check on that individual file.If that file satisfies teh condition put it in another file. Now... (1 Reply)
Discussion started by: vasuarjula
1 Replies

9. Shell Programming and Scripting

Unload utility with loop method

Hi, I just wonder why the unload tools from INFORMIX doesn't unload all required file to every output of mOutFile at the accumulative way OR my script has an error ? In fact it just unload to one single record at the latest. for mFile in x??? do echo "Now working with file "$mFile"... (1 Reply)
Discussion started by: cedrichiu
1 Replies

10. Shell Programming and Scripting

Method to exit a for loop

Hi All, Can someone let me know how i can exit a for loop without exiting the script itself .... will the break statement work .... please help .... -Regards (2 Replies)
Discussion started by: Rohini Vijay
2 Replies
Login or Register to Ask a Question