how to print specific lines or words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to print specific lines or words
# 1  
Old 07-18-2012
Question how to print specific lines or words

Hi,

Please have a look on below records.

Code:
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: The value of the row is: EMPLID = 220677 COMPANY = 919 BALANCE_ID = 0 BALANCE_YEAR = 2012
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: ORA-00001: unique constraint (SYSADM.PS_TAX_BALANCE) violated
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: DBMS.CODE=ORA-00001
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: The value of the row is: EMPLID = 220748 COMPANY = 919 BALANCE_ID = 0 BALANCE_YEAR = 2012
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: ORA-00034: Invalid Username and Passowrd
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: DBMS.CODE=ORA-00034
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: The value of the row is: EMPLID = 220748 COMPANY = 919 BALANCE_ID = 0 BALANCE_YEAR = 2012
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: ORA-00456: Invalid Employee ID
 
STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: DBMS.CODE=ORA-00456

In above scenario, there are 3 set of records for an individual employees (I mean first 3 records belong to EMPLID = 220677). Now I want to select only employee number and the error description for that employee.
In UNIX, how can I achieve the desired output in a new file like,

Code:
220677,unique constraint (SYSADM.PS_TAX_BALANCE) violated
220748,Invalid Username and Passowrd
220748,Invalid Employee ID


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by Sachin Lakka; 07-18-2012 at 06:22 AM.. Reason: code tags, see PM
# 2  
Old 07-18-2012
Try
Code:
awk '/EMPLID/{printf $10","}/ORA-[0-9]*:/{sub(".*ORA-[0-9]*: ","");printf $0"\n"}' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 07-18-2012
Hi


Code:
$ awk -F '[:=]' '/EMPLID/{printf "%d,",$4;getline;getline;print $3}' file
220677, unique constraint (SYSADM.PS_TAX_BALANCE) violated
220748, Invalid Username and Passowrd
220748, Invalid Employee ID


Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 4  
Old 07-18-2012
Try...
Code:
awk -F: '$3~/EMPLID/{split($3,a," ");printf "%s,",a[3]}$2~/^ ORA/{print $NF}' file1

This User Gave Thanks to Ygor For This Post:
# 5  
Old 07-18-2012
Thanks to all of you.

Ygor, its working perfectly.

Last edited by Sachin Lakka; 07-18-2012 at 10:26 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

How to print the specific lines?

I need to print specific lines 5,100,67,123 in a file. file name: today.csv (3 Replies)
Discussion started by: ramkumar15
3 Replies

3. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

4. Shell Programming and Scripting

Search words in a line and print next 15 lines.

I have a text file ( basically a log file) and i have 2 words (alpha, beta), Now i want to search these two words in one line and then print next 15 lines in a temp file. there would be many lines with alpha and beta But I need only last occurrence with "alpha" and "beta" and next 15 lines. ... (4 Replies)
Discussion started by: kashif.live
4 Replies

5. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

6. UNIX Desktop Questions & Answers

Display a specific words from a multiple lines

well, i am so not familiar with this kind of things but i am gonna explain extactly what i am looking for so hopfully someone can figure it out :) i have a command that shows memory usage besides the process name, for example(the command output): 500 kb process_1 600 kb process_2 700 kb... (4 Replies)
Discussion started by: Portabello
4 Replies

7. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

8. Shell Programming and Scripting

Keep lines with specific words up in an order

I hava a file with following data: number|CREDIT_ID|NULL date|SYS_CREATION_DATE|NULL varchar2|GGS_COMMIT_CHAR|NULL varchar2|GGS_OP_TYPE|NULL number|GGS_SCN|NULL| number|GGS_LOG_SEQ|NULL number|GGS_LOG_POS|NULL number|GGS_ORACREC_SCN|NULL varchar2|BATCH_ID|NULL char|GGS_IMAGE_TYPE|NULL ... (6 Replies)
Discussion started by: kolesunil
6 Replies

9. Shell Programming and Scripting

print specific lines

I have a text file made of different blocks separated by blank lines. I need to print the blocks with odd indexes. How can I get it with awk? For example i need to print the first and the third block of a file like this: asgdg sadsd ssgsdgd ass uff fedd sddddso ieeduydd dddee deeo ssancnc... (4 Replies)
Discussion started by: littleboyblu
4 Replies

10. Shell Programming and Scripting

Ignore some lines with specific words from file comparison

Hi all, I need help in doing this scenario. I have two files with multiple lines. I want to compare these two files but ignoring the lines which have words like Tran, Loc, Addr, Charge. Also if i have a word Credit in line, i want to tokenize (i.e string after character " ... (2 Replies)
Discussion started by: jakSun8
2 Replies
Login or Register to Ask a Question