The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
needed help in writing a script! wrapster Shell Programming and Scripting 5 06-13-2008 04:52 AM
Script needed vpandey Shell Programming and Scripting 3 03-04-2008 09:45 AM
Script information needed chris1234 UNIX for Dummies Questions & Answers 3 12-17-2007 07:35 PM
help needed! my first script fcbarcelona1984 Shell Programming and Scripting 1 11-04-2007 12:32 PM
Script Needed Dastard SUN Solaris 1 03-20-2007 10:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-19-2008
scuderiaf1 scuderiaf1 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
script help needed --- awk?

hello and thanks in advance.

I need to consolidate 2 records of data into 1 record.

here is a sample of the input:
------------------------------------------------------------------------------------------
totalcount fred thomas 99999.00 88888:00
total 77777.00
------------------------------------------------------------------------------------------
totalcount sally smither 99999.00 88888:00
total 77777.00 66666.00
------------------------------------------------------------------------------------------

Sample records are grouped within the '-------'. I need the data within the '---------' consolidated to look like the output format below

Fred, Thomas, 77777.00, 99999.00, 888888:00
Sally, Smither, 77777.00, 99999.00, 888888:00

Last edited by scuderiaf1; 06-21-2008 at 09:44 AM.. Reason: simplified the sample data
  #2 (permalink)  
Old 06-20-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
If I got it right, just remove the ------ lines and the empty ones, right?
Code:
grep -vE "^------|^$" infile > newfile
  #3 (permalink)  
Old 06-20-2008
scuderiaf1 scuderiaf1 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
zaxxon


Yes that is one of the things needed. I now under stand the -v and -E args of grep. ty.

I still need to consolidate a couple of fields on each record in between the '------' to one record...... does that make sense?

I have a base awk statement that i have started. I piped your recommended grep command to it.


Code:
grep -vE "^------|^$" $FILENAME | awk '$4="04" { print $1","$2 }'

Last edited by scuderiaf1; 06-21-2008 at 09:35 AM..
  #4 (permalink)  
Old 06-21-2008
scuderiaf1 scuderiaf1 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
I have a little time this morning to work on this script... any help would be appreciated. I will be posting the solution.


Go Ferrari!
  #5 (permalink)  
Old 06-21-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Code:
awk 'BEGIN{RS="-+"; OFS=", "} $2 {print $2, $3, $7, $4, $5 }' your-file
  #6 (permalink)  
Old 06-21-2008
scuderiaf1 scuderiaf1 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
ty.... that works.

I am attempting to read/learn about the important parts of that script/command. Is is a true statement that awk considers everthing between the record seperator RS as one record?

Wow clean and simple.

Again thank you and regrards,

T

I've sat at the beginning of Eau Rouge. That circuit is in a magical place.
  #7 (permalink)  
Old 06-21-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,926
A pure Korn shell solution
Code:
#!/usr/bin/ksh93

typeset -L1 -u firstF
typeset -L1 -u firstL

while read a b c d e
do
   if [[ $a == "totalcount" ]]; then
       nameF=$b
       nameL=$c
       numD=$d
       numE=$e
   fi
   if [[ $a == "total" ]]; then
       firstF=$nameF
       firstL=$nameL
       print "${firstF}${nameF#?}, ${firstL}${nameL#?}, $b, $numD, $numE"
   fi
done < file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0