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.
# 8  
Old 10-07-2012
Quote:
Originally Posted by emily
As you can see that with VM=0 it is also passing the digits following 8001..Smilie
one correction...
now try..
Code:
$awk -v VM="0" '/Jobs with Wrapper/ && $NF == VM{s=1}   /List of jobs/ && s{print $NF;s=""}' file
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

# 9  
Old 10-07-2012
Hi pamu,
Thanks,Yeah it is fine.

Would you tell me if I need to ask that :
Give me the digits for all other NO(ex 8001, 5001, 8221) except "0". How shall I do that?

Ans also explain the command a bit please.

emily
# 10  
Old 10-07-2012
Quote:
Originally Posted by emily
Would you tell me if I need to ask that :
Give me the digits for all other NO(ex 8001, 5001, 8221) except "0". How shall I do that?
Ans also explain the command a bit please.
for all digits except "0" try this..
Code:
awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{print $NF;s=""}' file

awk '/Jobs with Wrapper/ && $NF != 0{s=1} Here command check for the line which contains Jobs with Wrapper & $NF should be not equal zero. If both the conditions are satisfy then set s=1.
/List of jobs/ && s{print $NF;s=""}' Here command check for line which contains List of jobs & s presents. If both the conditions satisfy then print $NF and set s=""(null).

Hope this helps youSmilie
This User Gave Thanks to pamu For This Post:
# 11  
Old 10-07-2012
Hi Pamu,
Thanks it works but there is litl issue.
I tested 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.cern.ch/twiki/bin/view/CMS/JobExitCodes for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 8001 
  List of jobs: 381 
  See https://twiki.cern.ch/twiki/bin/view/CMS/JobExitCodes for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 5001
  List of jobs: 381,45,6,78,9,0,6,5,3-4
  See https://twiki.cern.ch/twiki/bin/view/CMS/JobExitCodes for Exit Code meaning

following is the output"
Code:
  $ awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{print $NF;s=""}' file.txt        
381
381,45,6,78,9,0,6,5,3-4

There is litl problem, I need no in the following orders to execute other command on them:
Code:
381,45,6,78,9,0,6,5,3-4

emily
# 12  
Old 10-08-2012
like this..?

Code:
$ awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p){p=p","$NF}else{p=$NF};s=""}END{print p}' file
381,381,45,6,78,9,0,6,5,3-4

or like this..?

Code:
$awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p){p=p","$NF}else{p=$NF};s=""}END{
num=split(p,arr,",");
for(i=1;i<=num;i++){
if(!x[arr[i]]++){if(FV){FV=FV","arr[i]}else{FV=arr[i]}}
}}END{print FV}' file
381,45,6,78,9,0,5,3-4

and as per your specified output.(but not clear what is your idea behind this)

Code:
$ awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p && $NF !~ p){p=p","$NF}else{p=$NF};s=""}END{print p}' file
381,45,6,78,9,0,6,5,3-4


Last edited by pamu; 10-08-2012 at 03:03 AM.. Reason: added info.
# 13  
Old 10-08-2012
Would this provide what you need:
Code:
awk '/Wrapper/ {tmp=$NF} /List/ && tmp {print tmp, $4}' file
8001 381
5001 381,45,6,78,9,0,6,5,3-4

If not, pls. provide an exact output sample derived from your above input.

Alternatively, if the "List of jobs" always is the next line after "Wrapper" line:
Code:
awk '/Wrapper/ && $NF {printf "%s: ",$NF; getline; print $4}' file


Last edited by RudiC; 10-08-2012 at 05:43 AM..
# 14  
Old 10-08-2012
Quote:
Originally Posted by RudiC
Would this provide what you need:
Code:
awk '/Wrapper/ {tmp=$NF} /List/ && tmp {print tmp, $4}' file
8001 381
5001 381,45,6,78,9,0,6,5,3-4

If not, pls. provide an exact output sample derived from your above input.

Alternatively, if the "List of jobs" always is the next line after "Wrapper" line:
Code:
awk '/Wrapper/ && $NF {printf "%s: ",$NF; getline; print $4}' file


Hi RudiC,
I needed the output from 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.cern.ch/twiki/bin/view/CMS/JobExitCodes for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 8001 
  List of jobs: 381 
  See https://twiki.cern.ch/twiki/bin/view/CMS/JobExitCodes for Exit Code meaning

crab:  ExitCodes Summary
 >>>>>>>>> 1 Jobs with Wrapper Exit Code : 5001
  List of jobs: 380,45,6,78,9,0,6,5,3-4
  See https://twiki.cern.ch/twiki/bin/view/CMS/JobExitCodes for Exit Code meaning

as following:
Code:
 381,380,45,6,78,9,0,6,5,3-4

i.e every followed digits except the digits following "0" in 'with Wrapper Exit Code : 0'

thanks

---------- Post updated at 04:09 AM ---------- Previous update was at 04:09 AM ----------

Quote:
Originally Posted by pamu
like this..?

Code:
$ awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p){p=p","$NF}else{p=$NF};s=""}END{print p}' file
381,381,45,6,78,9,0,6,5,3-4

or like this..?

Code:
$awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p){p=p","$NF}else{p=$NF};s=""}END{
num=split(p,arr,",");
for(i=1;i<=num;i++){
if(!x[arr[i]]++){if(FV){FV=FV","arr[i]}else{FV=arr[i]}}
}}END{print FV}' file
381,45,6,78,9,0,5,3-4

and as per your specified output.(but not clear what is your idea behind this)

Code:
$ awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p && $NF !~ p){p=p","$NF}else{p=$NF};s=""}END{print p}' file
381,45,6,78,9,0,6,5,3-4

Hi PamuSmilie
Second is what i need.

Thanks
pooja

---------- Post updated at 04:28 AM ---------- Previous update was at 04:09 AM ----------

Quote:
Originally Posted by pamu

Code:
$ awk '/Jobs with Wrapper/ && $NF != 0{s=1}   /List of jobs/ && s{if(p){p=p","$NF}else{p=$NF};s=""}END{print p}' file
381,381,45,6,78,9,0,6,5,3-4

or like this..?
Cant we assign it to some variable? so that i can use that later.
for example, mycomplee task is fllowing:
Code:
 
geThose no, which your code pass
381,381,45,6,78,9,0,6,5,3-4

then perform command like this,
Code:
crab -resubmit 381,381,45,6,78,9,0,6,5,3-4

/i have to pass those no to this command. 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