Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Retrieve the record using 2,2 lines and display the ouput in columnwise

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
chakkaravarthy's Unix or Linux Image
chakkaravarthy chakkaravarthy is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 9 September 2014, 8:14 AM EDT
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Retrieve the record using 2,2 lines and display the ouput in columnwise

This is my file
-------------

Code:
Using index 8 for dump of table abd_det. (6101)
Dumped 0 records. (13932)
Using index 10 for dump of table abscc_det. (6101)
Dumped 0 records. (13932)
Using index 14 for dump of table absc_det. (6101)
Dumped 254365 records. (13932)
Using index 16 for dump of table absd_det. (6101)
Dumped 0 records. (13932)
Using index 18 for dump of table absi_mstr. (6101)
Dumped 0 records. (13932)
Using index 19 for dump of table absl_det. (6101)
Dumped 0 records. (13932)
Using index 21 for dump of table absr_det. (6101)
Dumped 66359 records. (13932)

I want the output like this:
-------------------------

Code:
abd_det - 0
abscc_det-0
absc_det-254365
absd_det-0
absi_mstr-0
absl_det-0
absr_det-66359


Last edited by Franklin52; 06-23-2011 at 04:53 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
bartus11's Unix or Linux Image
bartus11 bartus11 is offline
Registered User
 
Join Date: Apr 2009
Last Activity: 3 August 2016, 11:03 AM EDT
Posts: 3,733
Thanks: 7
Thanked 1,153 Times in 1,123 Posts

Code:
perl -ln0e 'while (/table (\w+).*\nDumped (\d+)/g){print "$1 - $2"}' file

Sponsored Links
    #3  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
itkamaraj's Unix or Linux Image
itkamaraj itkamaraj is offline Forum Advisor  
Registered User
 
Join Date: Apr 2010
Last Activity: 5 November 2017, 9:59 PM EST
Posts: 3,148
Thanks: 45
Thanked 698 Times in 674 Posts

Code:
 
nawk ' /Using index/{printf ("%s - ",$8);getline;print $2}' test
abd_det. - 0
abscc_det. - 0
absc_det. - 254365
absd_det. - 0
absi_mstr. - 0
absl_det. - 0
absr_det. - 66359

    #4  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 5 December 2017, 5:22 PM EST
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
Another one:

Code:
awk -F"[. ]" '/Using/{printf $(NF-2) " - "} /Dumped/{print $2}' file

Sponsored Links
    #5  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
rdcwayx's Unix or Linux Image
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 13 September 2015, 8:58 PM EDT
Posts: 2,759
Thanks: 44
Thanked 420 Times in 408 Posts

Code:
awk -F "[. ]" '{printf (NR%2?$(NF-2):"-" $2 RS)}' infile

Sponsored Links
    #6  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
michaelrozar17's Unix or Linux Image
michaelrozar17 michaelrozar17 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 22 September 2016, 3:57 AM EDT
Location: IN
Posts: 894
Thanks: 15
Thanked 183 Times in 174 Posts
Sed way..

Code:
sed '/_/{N;s/.* \(.*\)\. [^ ]* \([0-9]*\) .*/\1-\2/}' inputfile > outfile

Sponsored Links
    #7  
Old Unix and Linux 06-23-2011   -   Original Discussion by chakkaravarthy
chakkaravarthy's Unix or Linux Image
chakkaravarthy chakkaravarthy is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 9 September 2014, 8:14 AM EDT
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Lot of Thanks for all the inputs.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
have to retrieve the distinct values (not duplicate) from 2nd column and display shirdi Shell Programming and Scripting 16 03-13-2010 09:02 AM
How can i retrieve some specific lines from a file using C vigneshinbox Programming 3 04-03-2009 06:44 PM
retrieve lines using sed, grep or awk learning_linux UNIX for Dummies Questions & Answers 3 03-25-2009 06:51 AM
Script to display record spanning over multiple lines Ujan Shell Programming and Scripting 2 03-05-2009 06:06 AM
retrieve lines that match a pattern fadista UNIX for Dummies Questions & Answers 2 12-10-2008 04:40 AM



All times are GMT -4. The time now is 12:03 PM.