extracting Number variable and the following digits.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting Number variable and the following digits.
# 1  
Old 10-06-2012
extracting Number variable and the following digits.

HI all,
I have output of something like this:
Code:
  
crab:  ExitCodes Summary
 >>>>>>>>> 12 Jobs with Wrapper Exit Code : 50117 
	 List of jobs: 1-12 
	See https:///twiki/something/ for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 5 Jobs with Wrapper Exit Code : 8001 
	 List of jobs: 1-3,7,8 
         See https://twiki/something/ for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 3 Jobs with Wrapper Exit Code : 8021 
	 List of jobs: 140,123,342
	See https://twiki/something/ for Exit Code meaning

I would like to recognize the no 50117 ( 8001,8021). And then then digits following this no: 1-12, [which is actually 1,2,3,4,5,6,7,8,9,10,11,12]
Once I have these digits I have to perform some command on these digits.

The no 50117 ( 8001,8021) is important. Reason is depending on this no, the different commands would be performed on the following digits.


Thanks in advance,
emily
# 2  
Old 10-06-2012
Like this?
Code:
awk '/Jobs with Wrapper Exit Code/{a=$NF}
/List of jobs/{print a,$NF;a=""}' file

# 3  
Old 10-06-2012
Quote:
Originally Posted by elixir_sinari
Like this?
Code:
awk '/Jobs with Wrapper Exit Code/{a=$NF}
/List of jobs/{print a,$NF;a=""}' file

hi,
Thanks for replying. I tried these command on the following txt file (file.txt):
Code:
 crab:  ExitCodes Summary
 >>>>>>>>> 568 Jobs with Wrapper Exit Code : 0 
  List of jobs: 1-95,97-114,116-121,123,125-129,131-159,161-184,186,188-191,194,199-206,208-230,232-233,235-236,238-239,241,243-246,248-250,252-255,258-264,266-280,282-288,290,292-296,298-300,302-304,306-312,314-316,318-319,321-373,375-380,382-458,460-500,502-511,513-516,519-524,526-531,533-574,576-597,599-613 
  See https://twiki/something

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 8001 
  List of jobs: 381 
  See https://twiki.soomething

and the output is here
Code:
   [extra]$ awk '/Jobs with Wrapper Exit Code/{a=$NF}
/List of jobs/{print a,$NF;a=""}' file.txt
0 1-95,97-114,116-121,123,125-129,131-159,161-184,186,188-191,194,199-206,208-230,232-233,235-236,238-239,241,243-246,248-250,252-255,258-264,266-280,282-288,290,292-296,298-300,302-304,306-312,314-316,318-319,321-373,375-380,382-458,460-500,502-511,513-516,519-524,526-531,533-574,576-597,599-613
8001 381

It seems to be working, but I doubt I did not get as how to use it. And also, I wonder if it would paste the NO as well like 8001 along with the digits?
Smilie


thanks
# 4  
Old 10-06-2012
Do you need this then?
Code:
awk '/Jobs with Wrapper Exit Code/{a=$NF}
/List of jobs/{n=split($NF,t,",")
for(i=1;i<=n;i++)
 if(split(t[i],t2,"-")==2)
  for(j=t2[1];j<=t2[2];j++)
   b=length(b)?b "," j:j
 else
  b=length(b)?b "," t[i]:t[i]
print a,b;a=b=""
}' file

which produces
Code:
0 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,
45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86
,87,88,89,90,91,92,93,94,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,116,117,118,119,120,121,123,
125,126,127,128,129,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,1
57,158,159,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,186,188,189,190,19
1,194,199,200,201,202,203,204,205,206,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229
,230,232,233,235,236,238,239,241,243,244,245,246,248,249,250,252,253,254,255,258,259,260,261,262,263,264,266,267,268,269,270,
271,272,273,274,275,276,277,278,279,280,282,283,284,285,286,287,288,290,292,293,294,295,296,298,299,300,302,303,304,306,307,3
08,309,310,311,312,314,315,316,318,319,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,34
2,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373
,375,376,377,378,379,380,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,
407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,4
38,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,460,461,462,463,464,465,466,467,468,469,47
0,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,502
,503,504,505,506,507,508,509,510,511,513,514,515,516,519,520,521,522,523,524,526,527,528,529,530,531,533,534,535,536,537,538,
539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,5
70,571,572,573,574,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,599,600,601,602,60
3,604,605,606,607,608,609,610,611,612,613
8001 381

on the mentioned (latest) input file.
# 5  
Old 10-06-2012
Hi,

I think, I did not clear my purpose. For the given input file, it is following :
Code:
  crab:  ExitCodes Summary
 >>>>>>>>> 568 Jobs with Wrapper Exit Code : 0 
  List of jobs: 1-95,97-114,116-121,123,125-129,131-159,161-184,186,188-191,194,199-206,208-230,232-233,235-236,238-239,241,243-246,248-250,252-255,258-264,266-280,282-288,290,292-296,298-300,302-304,306-312,314-316,318-319,321-373,375-380,382-458,460-500,502-511,513-516,519-524,526-531,533-574,576-597,599-613 
  See https://twiki/something

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 8001 
  List of jobs: 381 
  See https://twiki.soomething

I would like to provide no(=0) to some script and would like it give me back output as
Code:
 1-95,97-114,116-121,123,125-129,131-159,161-184,186,188-191,194,199-206,208-230,232-233,235-236,238-239,241,243-246,248-250,252-255,258-264,266-280,282-288,290,292-296,298-300,302-304,306-312,314-316,318-319,321-373,375-380,382-458,460-500,502-511,513-516,519-524,526-531,533-574,576-597,599-613

Then I would provide it another no (=8001) and would seek the output as
Code:
 381

Similarly, there would be different no string that I will provide and would seek the output.
And sometimes would seek the output for this case as well.
Code:
 pastes all digits following all no(like 8001) except 0

.

I hope it is clear now.

thanks
# 6  
Old 10-06-2012
something like this..?
VM=8001 as your input variable...

Code:
awk -v VM="8001" '/Jobs with Wrapper/ && $NF == VM{s=1}
  /List of jobs/ && s{print $NF}' file

# 7  
Old 10-06-2012
Hi,
I tried it over this file
Code:
crab:  ExitCodes Summary
 >>>>>>>>> 568 Jobs with Wrapper Exit Code : 0 
  List of jobs: 1-95,97-114,116-121,123,125-129,131-159,161-184,186,188-191,194,199-206,208-230,232-233,235-236,238-239,241,243-246,248-250,252-255,258-264,266-280,282-288,290,292-296,298-300,302-304,306-312,314-316,318-319,321-373,375-380,382-458,460-500,502-511,513-516,519-524,526-531,533-574,576-597,599-613 
  See https://twiki.somthing for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 8001 
  List of jobs: 381

Following are the command and the output:
Code:
 
 [extra]$ awk -v VM="0" '/Jobs with Wrapper/ && $NF == VM{s=1}
  /List of jobs/ && s{print $NF}' file.txt
1-95,97-114,116-121,123,125-129,131-159,161-184,186,188-191,194,199-206,208-230,232-233,235-236,238-239,241,243-246,248-250,252-255,258-264,266-280,282-288,290,292-296,298-300,302-304,306-312,314-316,318-319,321-373,375-380,382-458,460-500,502-511,513-516,519-524,526-531,533-574,576-597,599-613
381

[extra]$ awk -v VM="8001" '/Jobs with Wrapper/ && $NF == VM{s=1}
  /List of jobs/ && s{print $NF}' file.txt
381

As you can see that with VM=0 it is also passing the digits following 8001..Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash detecting number of digits in line

Hi I have a problem, I am attempting to write a bash script that goes through a file and can determine how many characters are at a set point in a line starting with QTY+113:100:PCE, If it detects 3 digits (number in bold) then pad it out with 12 zero's If there are only two digits then pad it... (8 Replies)
Discussion started by: firefox2k2
8 Replies

2. Shell Programming and Scripting

Find number of digits in a word

HI, Can you tell me how to find the number of digits in a word. $cat data.txt +123456ad 87645768 Output should be 6 8 (5 Replies)
Discussion started by: ashwin3086
5 Replies

3. Shell Programming and Scripting

awk changes to cut number of digits

HCPM1ONDB00014800011800000589009211201 L201307022013070228AUD 00000000031. 000965105800000000000000000000000 MOBITV KEYA ... (4 Replies)
Discussion started by: mirwasim
4 Replies

4. Shell Programming and Scripting

Eliminating duplicate lines via specified number of digits

Hello, This is similar to a previous post, where I was trying to eliminate lines where column #1 is duplicated. If it is a duplicate, the line with the greater value in column #2 should be deleted. In this new case, I need to test duplication with the first three digits in column #1 (ignoring the... (6 Replies)
Discussion started by: palex
6 Replies

5. Shell Programming and Scripting

summing the digits of a binary nuMBER

please help me write a perl program to find the difference of 1 and zeros of a 6 digit binary number. eg If input is 111100 expected output +2 if input is 000011 expected output -2 input is 000111 expected output 0 (2 Replies)
Discussion started by: dll_fpga
2 Replies

6. Shell Programming and Scripting

Need to represent a number in 99999999 format(8 digits)

Hi all, i have to create a file having an 8-digit sequence number, that will start by name file_00000001.cvs at first time, the next day the file will be named file_00000002.cvs and so on. How can i do this in my script please, specially that i will need a counter that increments this number... (10 Replies)
Discussion started by: Eman_in_forum
10 Replies

7. Shell Programming and Scripting

number of digits after decimal

Hi All, I have a file of decimal numbers, cat file1.txt 1.1382666907 1.2603107334 1.6118799297 24.4995857056 494.7632588468 560.7633734425 ..... I want to see the output as only 7 digits after decimal (5 Replies)
Discussion started by: senayasma
5 Replies

8. Shell Programming and Scripting

Use match() in nawk to find digits in number

Hi, I just need to check whether number of digits in a phone number is 10 or not. If I am not wrong regex will be: {9} I have to use this inside nawk as this is a small portion of a big program. nawk ' BEGIN { RS="";FS=";"; regex="{9}"; } { for (i=1;i<=NF;i++) { if... (6 Replies)
Discussion started by: shekhar2010us
6 Replies

9. Shell Programming and Scripting

Count number of digits in a word

Hi all Can anybody suggest me, how to get the count of digits in a word I tried WORD=abcd1234 echo $WORD | grep -oE ] | wc -l 4 It works in bash command line, but not in scripts :mad: (12 Replies)
Discussion started by: ./hari.sh
12 Replies

10. UNIX for Advanced & Expert Users

restrain the number of digits of a PID

How is it possible under UNIX to restrain the number of digits of the PID number? For instance, we have a product that generates a PID of 7 digits, and we would like to have only 6 digits maximum instead for the PID. Thank you for your help. (1 Reply)
Discussion started by: mlefebvr
1 Replies
Login or Register to Ask a Question