Assigning variable using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning variable using script
# 1  
Old 09-30-2012
Assigning variable using script

Hi all,
I have to write script to make my usual job easy. Basically it involve reading a output of following pattern:
Code:
crab:  ExitCodes Summary
 >>>>>>>>> 45 Jobs with Wrapper Exit Code : 0 
	 List of jobs: 607-608,616,619,628,630,632,638-640,646-647,658,666,673-674,680,687,692,699-700,702,708,720,725,731,735,737,740,743,748,750,752,754,764,769,771-772,778,781,786,790,796,799,1114 
	See https:// for Exit Code meaning

crab:   1161 Total Jobs 
 >>>>>>>>> 41 Jobs Submitted 
	List of jobs Submitted: 5,101,106,255,280,288,310,313-314,401-403,405,718,723,766,776-777,785,797,986-987,991,997,999,1053-1054,1057,1065,1069,1076,1083,1092,1095,1106,1115,1119-1120,1127-1128,1137 
 >>>>>>>>> 520 Jobs Scheduled 
	List of jobs Scheduled: 1-2,7-8,10,13,15-18,22-23,26,31-32,34-35,39-40,42,44-47,51,54-58,61,63,66-69,72,74,76,78-80,86-88,92-97,100,103,114-115,117,119,125,130-131,138,140,144,147,149-150,158,161-163,165,169-170,172-173,176,178-180,184-187,189,192,196,198,204,208,218,221,225,228,231,236,239,243-244,246,248,250-251,253-254,256,258,261,264-265,267,270,276-279,281-282,284,287,299-300,302-303,309,311,316-321,323-325,328,332,336,338,341,345,349,352-355,358,360,363-365,371-372,376,378-380,382,385,388-390,395-398,404,406,409,411,413,415-416,418-419,422-423,426-427,431,438-439,441-442,444-446,448,451,453,455-460,462,468,476,478-490,494-495,498,502,504-505,507,513,517,519-520,522,524,526,531,533,537-538,542-543,545-547,550,555,557-558,561-562,564-566,568,573,575-576,583,589,592-593,595,598-599,601-606,609,611,613,615,617-618,620-623,625-627,629,631,634-636,641-643,645,648-657,659-661,663-665,667-672,676-679,681-686,688-689,691,693-698,701,703-707,709-710,712-717,719,721-722,724,726-730,732-734,736,738-739,741-742,744-747,749,751,753,755-760,762-763,765,767-768,773-775,779-780,782-784,787-789,791-795,798,800,803-804,806,808-809,816,818-819,824,834-835,842-843,845,849,851,855,859,861,863-864,867,873,877-879,885,888-889,893,896,898,901,906,917-920,923-924,929,931-934,937,941,945,950-951,953,958-961,963,966,968-969,972,974-975,977,980,982,984-985,988-989,996,998,1005-1007,1009-1010,1013,1018,1022,1024-1025,1027,1030,1032,1035,1039-1040,1043,1045-1046,1048,1052,1055-1056,1059,1061-1062,1070,1072-1075,1077-1078,1081,1084-1085,1087-1090,1094,1096-1097,1099,1103-1105,1109-1110,1112,1116-1118,1121,1129,1131,1140,1152-1153 
 >>>>>>>>> 555 Jobs Aborted
	You can resubmit them specifying JOB numbers: crab -resubmit <List of jobs>
	List of jobs: 3-4,6,9,11-12,14,19-21,24-25,27-30,33,36-38,41,43,48-50,52-53,59-60,62,64-65,70-71,73,75,77,81-85,89-91,98-99,102,104-105,107-113,116,118,120-124,126-129,132-137,139,141-143,145-146,148,151-157,159-160,164,166-168,171,174-175,177,181-183,188,190-191,193-195,197,199-203,205-207,209-217,219-220,222-224,226-227,229-230,232-235,237-238,240-242,245,247,249,252,257,259-260,262-263,266,268-269,271-275,283,285-286,289-298,301,304-308,312,315,322,326-327,329-331,333-335,337,339-340,342-344,346-348,350-351,356-357,359,361-362,366-370,373-375,377,381,383-384,386-387,391-394,399-400,407-408,410,412,414,417,420-421,424-425,428-430,432-437,440,443,447,449-450,452,454,461,463-467,469-475,477,491-493,496-497,499-501,503,506,508-512,514-516,518,521,523,525,527-530,532,534-536,539-541,544,548-549,551-554,556,559-560,563,567,569-572,574,577-582,584-588,590-591,594,596-597,600,610,612,614,624,633,637,644,662,675,690,711,761,770,801-802,805,807,810-815,817,820-823,825-833,836-841,844,846-848,850,852-854,856-858,860,862,865-866,868-872,874-876,880-884,886-887,890-892,894-895,897,899-900,902-905,907-916,921-922,925-928,930,935-936,938-940,942-944,946-949,952,954-957,962,964-965,967,970-971,973,976,978-979,981,983,990,992-995,1000-1004,1008,1011-1012,1014-1017,1019-1021,1023,1026,1028-1029,1031,1033-1034,1036-1038,1041-1042,1044,1047,1049-1051,1058,1060,1063-1064,1066-1068,1071,1079-1080,1082,1086,1091,1093,1098,1100-1102,1107-1108,1111,1113,1122-1126,1130,1132-1136,1138-1139,1141-1151,1154-1161 
 >>>>>>>>> 45 Jobs Cleared
	List of jobs: 607-608,616,619,628,630,632,638-640,646-647,658,666,673-674,680,687,692,699-700,702,708,720,725,731,735,737,740,743,748,750,752,754,764,769,771-772,778,781,786,790,796,799,1114 

crab:  You can also follow the status of this task on :
	CMS Dashboard: http://dashb-cms-

I would like to write a script which look for the common text like "Aborted" , ("Scheduled", "Submitted") and some VARIABLE can be assigned to the rest of the no appearing below so that I could be able to perform some command on those no.

Thanks in advance,
emily
# 2  
Old 09-30-2012
Try:
Code:
grep "jobs Scheduled" file | sed 's/.*: //;s/,/\n/g' | while read job; do 
  echo $job
done

Change "echo $job" to whatever command you need. To get Aborted and Submitted jobs, just change grep argument.
# 3  
Old 09-30-2012
Hi,
Thanks for the promt reply.
It work fine for "Scheduled", but for "Aborted" it did not work.

However, for the output, I will need the no in the same pattern as they are in the Infile like, 1-2,3-4,5, 8,

Code:
 grep "jobs Scheduled" dataB_status.log  | sed 's/.*: //' | tr ',' '\n' | while read job; do echo $job; done
1-2
7-8
10
13
15-18
22-23
26
31-32
34-35
39-40
42

Also When I tried using string "Aborted" as following, it did not give the required output Smilie
Code:
  
$grep "jobs Aborted" dataB_status.log  | sed 's/.*: //' | tr ',' '\n' | while read job; do echo $job; done
$ grep "Jobs Aborted" dataB_status.log  | sed 's/.*: //' | tr ',' '\n' | while read job; do echo $job; done
>>>>>>>>> 47 Jobs Aborted

Infile
Code:
  >>>>>>>>> 47 Jobs Aborted
	You can resubmit them specifying JOB numbers: crab -resubmit <List of jobs>
	List of jobs: 188,190,195,235,237-238,242,247,262-263,268,329,333,357,362,366,373,381,386,391,408,412,414,425,433,435,440,449,463,466,475,493,503,511,515,525,529,535-536,560,563,570,572,574,580,584,633

# 4  
Old 09-30-2012
-A 2 tell grep to get the +2 line from the string "Jobs Aborted" because that is the line containing the numbers.

Code:
grep -A 2 "Jobs Aborted" file | sed 's/.*: //;s/,/\n/g' | while read job; do    
  echo $job
done

# 5  
Old 09-30-2012
Hi,
Thanks for the reply. It did work. :-)
But again the format of the output is not the same as I wish.
I would like it to be in a row with no space and with "," to seperate:
Code:
1,2-3,6,7,500-600

Also, please let me know how does it command work. That will be learning part for me :-)

Thanks again,
# 6  
Old 09-30-2012
Quote:
Originally Posted by emily
Hi,
Thanks for the reply. It did work. :-)
But again the format of the output is not the same as I wish.
I would like it to be in a row with no space and with "," to seperate:
Code:
1,2-3,6,7,500-600

Also, please let me know how does it command work. That will be learning part for me :-)

Thanks again,

I could explain but the sed is very difficult to explain. You need to learn regular expressions if you don't know that already to understand the sed commands.

I guess this command will give you the output you are looking for

Code:
grep -A 2 "Jobs Aborted" file | sed 's/.*: //' | grep -E '^[0-9]+'

# 7  
Old 09-30-2012
Hi,
It did work fine.
I have used sed for the simple task like renaming some common text in the file.
But whenever it comes to non-regular expression use, I am complete naive for it.

Code:
sed -e "s/oldname/newname/" file > file1

Also what does this command does
Code:
 grep -E '^[0-9]+'

?
It seems to aligned them, but how it is suppose to be used?

thanks again,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning any number to the variable in cshell script

Hello Guys, I would like to ask you for a favor. Could you please help me how can I assign any number as the parameter to a, from stdin (-c), in the following command line by using the 'switch' in a script? awk '$8>a {print "File name:" $5,$8}' I would also appreciate if you can share any... (1 Reply)
Discussion started by: Padavan
1 Replies

2. Shell Programming and Scripting

Assigning value to a variable

Unable to get the value to a variable. set -x cd $HOME echo "Enter the server name" read a echo $a i=4 j=1 k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j` echo $k When I do the same in command line it works, however the same does not work when I provide that in the... (1 Reply)
Discussion started by: venkidhadha
1 Replies

3. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

my script is some thing like this i11="{1,2,3,4,5,6,7,8,9,10,11,}" echo "enter value" read value ..............suppose i11 x="$value" echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,} but its showing "i11" only. plz help me out to get desired... (10 Replies)
Discussion started by: sagar_1986
10 Replies

5. Shell Programming and Scripting

Script stops running after assigning empty string for a variable

Hi, This is the first time I see something like this, and I don't why it happens. Please give me some help. I am really appreciate it. Basically I am trying to remove all empty lines of an input.. #!/bin/bash set -e set -x str1=`echo -e "\nhaha" | grep -v ^$` #str2=`echo -e "\n" |... (4 Replies)
Discussion started by: yoyomano
4 Replies

6. Shell Programming and Scripting

Assigning value to script variable

I am trying to assign the value returned by wc command to a script variale. Code: FILES_NAME='files_list'; NO_OF_FILES =${wc -l $FILES_NAME}`; When the above code is run : it throws the error ${wc -l $FILES_NAME}: The specified substitution is not valid for this command. what is the... (6 Replies)
Discussion started by: hiten.r.chauhan
6 Replies

7. Shell Programming and Scripting

Assigning return value of an embedded SQL in a shell script variable

I've a script of the following form calling a simple sql that counts the no of rows as based on some conditions. I want the count returned by the sql to get assigned to the variable sql_ret_val1. However I'm finding that this var is always getting assigned a value of 0. I have verified by executing... (1 Reply)
Discussion started by: MxC
1 Replies

8. Shell Programming and Scripting

ksh help assigning specific values to variable in script

Hi - Help needed. I have an input file that looks something like this, but with a lot more entries: A Customer1 B 4500 C 8000 A Customer2 B 6422 C 8922 I need to be able to print details for each customer on one line per customer. ie. if I could print these to a file and then cat... (3 Replies)
Discussion started by: frustrated1
3 Replies

9. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

10. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question