Need help in awk scripting

Hi

I am beginner of shell/AWK scripting , can you please help me in select particular column and column between two pattern from a multiple column file.

file1.txt

number status  date1  date2              description                                                         category                                     type                 service  assigned_to     reported_to  envioment 
=====  ====   ===      =====            =============                                             =============                        =====             =======  =========     ======== ======
12345 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading init Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar  DBA PROD
23456 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Sizing Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar  DBA TEST
45678 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info Oracle Services - Trouble Tk Ticket, Auto   DBA_SERVICE chadda,Deepak kumar  DBA QUALITY
24578 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn Oracle Services - Trouble Tk Ticket, Auto   DBA_SERVICE shama,Vijay Kumar  DBA PROD
45890 open 28/06/13 28/06/13  nl21a00is-centerdb001:testingQA:FSFO has configuration errors Oracle Services - Trouble Tk Ticket, Auto   DBA_SERVICE Reddy,Ajay rao   DBA PROD

I want to select " number, description, assigned_to "

description field end before category field start "Oracle Service-Trouble Tk"
assigned_to field is between two pattern DBA_SERVICE and DBA e.g. chadda,Deepak kumar

desire out out

out.txt

12345   nl21a00is-centerdb001:ncdbareq:Error in loading init  chadda,Deepak kumar  
23456   nl21a00is-centerdb001:ncdbareq:Error in loading Sizing  chadda,Deepak kumar  
45678   nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info chadda,Deepak kumar  
24578   nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn shama,Vijay Kumar 
45890   nl21a00is-centerdb001:testingQA:CSSO has configuration errors  Reddy,Ajay rao   

i want to select column1 and column5 (all description column before "category" column and third last column(which is in-between to pattern DBA_SERVICE and DBA)

Try this one..

awk '{print $1,$5,$6,$7,$8,$18,$19}' file1.txt

will this work?

 
sed 's/\(.*\)Oracle Services .* DBA_SERVICE\(.*\)DBA.*/\1\2/g' filename|awk 'NR>2{$2=$3=$4="";print}'
Vijay-G:~ vijaygarhewal$ awk '{print $1,$5,$6,$7,$8,$18,$19}' file1.txt
12345 nl21a00is-centerdb001:ncdbareq:Error in loading init chadda,Deepak kumar
23456 nl21a00is-centerdb001:ncdbareq:Error in loading Sizing chadda,Deepak kumar
45678 nl21a00is-centerdb001:ncdbareq:Error in loading DBMS DBA_SERVICE chadda,Deepak
24578 nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn shama,Vijay Kumar
45890 nl21a00is-centerdb001:testingQA:FSFO has configuration errors Reddy,Ajay rao

but Its not containing all the description column...In third line description field contain "nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info"

the "info" is missing in this output.

I have already tried this ...the description column may contain 3 or 4 or 5 or 6 or 7....or 10 field but It is sure new column will start with "Oracle Services - Trouble Tk"

so we need to read all the field of description column and stop reading once we get "Oracle Services - Trouble Tk" and print.

can you please provide syntax for this..

---------- Post updated at 08:05 AM ---------- Previous update was at 08:01 AM ----------

This is not giving any output...

Vijay-G:~ vijaygarhewal$ cat file1.txt
12345 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading init Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar  DBA PROD
23456 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Sizing Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar  DBA TEST
45678 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info Oracle Services - Trouble Tk Ticket, Auto   DBA_SERVICE chadda,Deepak kumar  DBA QUALITY
24578 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn Oracle Services - Trouble Tk Ticket, Auto   DBA_SERVICE shama,Vijay Kumar  DBA PROD
45890 open 28/06/13 28/06/13  nl21a00is-centerdb001:testingQA:FSFO has configuration errors Oracle Services - Trouble Tk Ticket, Auto   DBA_SERVICE Reddy,Ajay rao   DBA PROD
Vijay-G:~ vijaygarhewal$ 
Vijay-G:~ vijaygarhewal$ 
Vijay-G:~ vijaygarhewal$ sed 's/\(.*\)Oracle Services .* DBA_SERVICE\(.*\)DBA.*/\1\2/g' file1.txt|awk 'NR>2{$2=$3=$4="";print}'

Please use code tags for posting code fragments or data samples.

Try this:

awk 'NR>2{n=$1;gsub(/.*[0-9]*\/[0-9]*\/[0-9]* |Oracle.*_SERVICE|DBA[ ].*/,X);print n,$0}' file

This looks good..can you explain me the syntax..

please help me to understandb gsub function..

awk '
NR > 2 {                                                        # Skip first 2 lines
 n = $1                                                          # Set n = 1st field
 # Substitute every chars until date with null (.*[0-9]*\/[0-9]*\/[0-9]*)
 #12345 open 27/06/13 28/06/13 nl21a00is-centerdb001:ncdbareq:Error in loading init Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar DBA PROD

 # Substitute Oracle followed by zero or more occurrence of any chars until _SERVICE (Oracle.*_SERVICE)
 #nl21a00is-centerdb001:ncdbareq:Error in loading init Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar DBA PROD

 # Substitute DBA followed by space followed by zero or more occurrence of any chars (DBA[ ].*)
 #nl21a00is-centerdb001:ncdbareq:Error in loading init chadda,Deepak kumar DBA PROD

 gsub(/.*[0-9]*\/[0-9]*\/[0-9]* |Oracle.*_SERVICE|DBA[ ].*/,X)
 # Print n , $0
 print n,$0
        }
' file
1 Like

Hi

I am begineer for awk/shell scripting...I have two files file1.txt and file2.txt.

want to print some column(number,status,date1,date2,description(descrption column end before category column start with'Oracle Services') and assigned_to column from file1.txt ...If the assigned_to name in file2.txt matches with assinged_to name in file1.

file1.txt
----------

number status  date1  date2     description                                              category                              type                 service  assigned_to     reported_to  envioment 
=====  ====   ===      =====    =============                                             =============                        =====             =======  =========     ======== ======
34567 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading init Oracle Services - Trouble Tk Ticket, Auto  DBA_SERVICE chadda,Deepak kumar  DBA PROD
45678 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Sizing Oracle Services - Trouble Tk Ticket, Auto  DBA_Ticket chadda,Deepak kumar  DBA TEST
43567 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info Oracle Services - Trouble Tk Ticket, Auto   DBA_Group chadda,Deepak kumar  DBA QUALITY
24578 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn Oracle Services - Trouble Tk Ticket, Auto   DBA_GrouP Sharma,Vijay Kumar  DBA PROD
45890 open 28/06/13 28/06/13  nl21a00is-centerdb001:testingQA:FSFO has configuration errors Oracle Services - Trouble Tk Ticket, Auto   SA_SERVICE Reddy,Ajay rao   DBA PROD
43599 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info Oracle Services - Trouble Tk Ticket, Auto   DBA_Group Agarwal,ravi kumar  DBA QUALITY
25578 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn Oracle Services - Trouble Tk Ticket, Auto   DBA_GrouP Pandit,Ashok Kumar  DBA PROD
51890 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading init Oracle Services - Trouble Tk Ticket, Auto   SA_SERVICE Reddy,Ajay rao   DBA PROD

file2.txt
-----------

Assigned_to
===========
Sharma,Vijay Kumar
Soni,Amit Kumar
Rajput,Anupam 
chadda,Deepak kumar
Thakral,Raj Singhalese
Sahu,chanchal ram
Reddy,Ajay rao

I have two files file1.txt and file2.txt.

want to print some column(number,status,date1,date2,description(descrption column end before category column start with'Oracle Services') and assigned_to column from file1.txt ...If the assigned_to name in file2.txt matches with assinged_to name in file1.

desirous output

34567 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading init chadda,Deepak kumar 
45678 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Sizing chadda,Deepak kumar 
43567 open 27/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading DBMS info chadda,Deepak kumar 
24578 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading Trig/Proc/Syn Sharma,Vijay Kumar 
51890 open 28/06/13 28/06/13  nl21a00is-centerdb001:ncdbareq:Error in loading init Reddy,Ajay rao