help needed to put instance numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help needed to put instance numbers
# 1  
Old 07-16-2012
MySQL help needed to put instance numbers

Hi All

I need help

am having a source file as below

emp
dept
class
subclass
region
country
division



first i need to get line count and i need to divide by 3 it is an parameter passing value

number of lines 7

7/3 = 2.33


i need output like below

1,emp
1,dept
1,class
2,subclass
2,region
2,country
3,division




Thanks in Advance
# 2  
Old 07-16-2012
How should the output look like if there are say 10 lines?
# 3  
Old 07-16-2012
Have you tried writing a script??
# 4  
Old 07-16-2012
10/3=3.2

1,emp
1,dept
1,class
2,subclass
2,region
2,country
3,division
3,...
3,.....
4,....

---------- Post updated at 02:06 AM ---------- Previous update was at 01:57 AM ----------

hi PikK45

am totally blank

please help
# 5  
Old 07-16-2012
Code:
awk 'BEGIN{i=1} {print i "," $0} NR%3==0 {i++}' file

# 6  
Old 07-16-2012
hi
balajesuri


awk 'BEGIN{i=1} {print i "," $0} NR%1==0 {i++}' t1

when i execute this it is coming as
1,emp
2,dept
3,class
4,subclass
5,region
6,country
7,division


i need to come as

1,emp
1,dept
1,class
1,subclass
1,region
1,country
1,division
# 7  
Old 07-16-2012
Just remove the
Code:
 {i++}

block Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hint needed for incrementing numbers

Hi All Been trying to get something working but having some trouble in unix bash or ksh scripting. Im trying to increment once a condition has been met Say I have a file that contains: apple orange banana grapes dates kiwi What im after is once a counter has reached every second... (3 Replies)
Discussion started by: chandika_diran
3 Replies

2. Shell Programming and Scripting

Put numbers after word

Hello I have an file with this content -------------------------------------------- timer one timer two timer three timer four timer five timer six timer seven ------------------------------------------- And I want the following output.... (4 Replies)
Discussion started by: thailand
4 Replies

3. Shell Programming and Scripting

Help extracting single instance of numbers which repeat

Hi, the title isn't very descriptive but it'll be easier to explain what I need if I write out the coordinates from which I need to extract certain information: ATOM 2521 C MAM X 61 44.622 49.357 12.584 1.00 0.00 C ATOM 2522 H MAM X 61 43.644 49.102 12.205 ... (10 Replies)
Discussion started by: crunchgargoyle
10 Replies

4. Shell Programming and Scripting

Put double quotes around numbers

Hi, consider a file which has data such as "random text",912345,"54","finish" "random text",9991236745,"9954","finish" I want to replace the numbers that don't have double quotes around them with ones that do; so the output should be "random text","912345","54","finish" "random... (4 Replies)
Discussion started by: Storms
4 Replies

5. AIX

HACMP 5.4.1->5.5 offline upgrade - different instance numbers ?

Hello, I did offline HACMP(PowerHA) upgrade 5.4.1 to 5.5 - basically stopped HACMP services and upgraded cluster.* filesets. Tried to start services again - topsvcs refused to start on second node complaining that node instance numbers are different - and indeed they are different. This is... (2 Replies)
Discussion started by: vilius
2 Replies

6. Shell Programming and Scripting

Put numbers against the words

Hi All, I tried to solve this but the result gives me all zeros for one file. I failed to do for all 500 files. I have some 500 files with the extension .dat I have another set of files; 500 in number with extension .dic I created these .dic files by using sort -u from the actual .dat files.... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

7. Shell Programming and Scripting

sed appending needed only after first instance

Hi, Here is my piece of code used with sed in shell script: sed -i '/<falsemodule-option>/ a\<LdapLogin>' myxmlfile The problem that i am facing with the above is that in 'myxml' file i have mulitple instances of <falsemodule-option> so when i execute the above sed command, it is appending... (10 Replies)
Discussion started by: sunrexstar
10 Replies

8. Solaris

help needed to put machine in domain

Hi All, I am working on Solaris sparc 9 and my computer name is mgsun. I want to bring this machine to a specific domain (e.g.-xx.xx.org). So please help me to do the same.. thanks in Advance... (4 Replies)
Discussion started by: smartgupta
4 Replies

9. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

10. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies
Login or Register to Ask a Question