awk finding counting sequence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk finding counting sequence
# 8  
Old 10-27-2011
Quote:
Originally Posted by ahamed101
It works for me though...--ahamed
It was the field seperator I omittedSmilie.

Now I encounter another ommitance. When the first field of a line has only one sequence to be calculated then this field will be ommited in the output. Like this.

Input:
HTML Code:
serv10b, 804, 808, 929/32, 940/42, 977/1020, 1240/41, 1246, 1254/56, 1353, 1377/82.
serv11, 492/538.
...

output:

HTML Code:
serv10b, 804, 808,  929, 930, 931, 932,  940, 941, 942,  977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020,  1240, 1241, 1246,  1254, 1255, 1256, 1353,  1377, 1378, 1379, 1380, 1381, 1382.,
serv11,


Last edited by sdf; 10-27-2011 at 10:33 AM..
# 9  
Old 10-27-2011
It works for me mate!

Code:
root@bt:/tmp# cat input_file 
serv10b, 804, 808, 929/32, 940/42, 977/1020, 1240/41, 1246, 1254/56, 1353, 1377/82.
serv11, 492/538.

root@bt:/tmp# awk -F"," '{
        printf $1 FS
        for(i=2;i<=NF;i++)
        {
                if(!match($i,"/")){
                        printf $i FS
                        continue
                }
                split($i,arr,"/")
                a=arr[1]; b=arr[2]
                if(arr[1]>arr[2])
                {
                        num=substr(arr[1], 1, length(arr[1])-length(arr[2]))
                        b=num arr[2]

                }
                for(j=a;j<=b+0;j++)
                {
                        printf " "j FS
                }
        }
        printf "\n"
}
' input_file 
serv10b, 804, 808,  929, 930, 931, 932,  940, 941, 942,  977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 
992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 
1014, 1015, 1016, 1017, 1018, 1019, 1020,  1240, 1241, 1246,  1254, 1255, 1256, 1353,
serv11,  492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 
516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528,529, 530, 531, 532, 533, 534, 535, 536, 537, 538,

--ahamed
# 10  
Old 10-27-2011
Quote:
Originally Posted by ahamed101
It works for me mate!

--ahamed
Then it must have to do something with gawk on windowsSmilie. I need to change the OS. Perhabs it has something to do with the field seperator outside the script. Will check on this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sequence of conditions awk

hello gurus, I want to use an associative array from a file to populate a field of another file, by matching several columns in order of priority. If the first column matches, then i dont want to match $2. Similarly I only want to match $3 when $1 and $2 are not in associative array. For the... (6 Replies)
Discussion started by: ritakadm
6 Replies

2. UNIX for Dummies Questions & Answers

awk code to reconstruct sequence from alignment

Hi Everyone, I need some help to construct a long 'Sbjct' string from the following input using incremental order of 'Sbjct' starting number (e.g. 26325115,33716368,33769033,34869860 etc.) Different 'Sbject' string will be separated by 'NNNN's as: ... (6 Replies)
Discussion started by: Fahmida
6 Replies

3. Shell Programming and Scripting

awk counting question

Probably a simple to this, but unsure how to do it. I would prefer an AWK solution. Below is the data set. 1 2 3 2 5 7 4 6 9 1 5 4 8 5 7 1 1 10 15 3 12 3 7 9 9 8 10 4 5 2 9 1 10 4 7 9 7 12 6 9 13 8 For the second... (11 Replies)
Discussion started by: mollydog11
11 Replies

4. Shell Programming and Scripting

Counting Fields with awk

ok, so a user can specify options as is shown below: ExA: cpu.pl!23!25!-allow or ExB: cpu.pl!23!25!-block!all options are delimited by the exclamation mark. now, in example A, there are 4 options provided by the user. in example B, there are 5 options provided by the user. ... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

counting using awk

Hi, I want to perform a task using shell script. I am new to awk programming and any help would be greatly appreciated. I have the following 3 files (for example) file1: Name count Symbol chr1_1_50 10 XXXX chr3_101_150 30 YYYY File2: Name ... (13 Replies)
Discussion started by: Diya123
13 Replies

7. Shell Programming and Scripting

suffix a sequence in awk

hi I have a string pattern like ... ... 000446448742 00432265 040520100408 21974435 DEWSWATER GARRIER AAG IK4000 N 017500180000000000000000077000000000100 000446448742 00580937 040520100408 32083576 PEWSWATER BARRIER DAG GK4000 ... (6 Replies)
Discussion started by: zainravi
6 Replies

8. Shell Programming and Scripting

Counting with Awk

I need "awk solution" for simple counting! File looks like: STUDENT GRADE student1 A student2 A student3 B student4 A student5 B Desired Output: GRADE No.of Students A 3 B 2 Thanks for awking! (4 Replies)
Discussion started by: saint2006
4 Replies

9. Shell Programming and Scripting

Counting records with AWK

I've been working with an awk script and I'm wondeing id it's possible to count records in a file which DO NOT contain, in this instance fields 12 and 13. With the one script I am wanting to display the count for the records WITH fields 12 and 13 and a seperate count of records WITHOUT fields... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

10. UNIX for Dummies Questions & Answers

how can i isolate the random sequence of numbers using awk?

as you can see there is a delimiter after c8 "::". Awk sees the rest as fields because it doesn't recognize spaces and tabs as delimiters. So i am basically looking to isolate 20030003ba13f6cc. Can anyone help? c8::20030003ba13f6cc disk connected configured unknown (2 Replies)
Discussion started by: rcon1
2 Replies
Login or Register to Ask a Question