The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
editing ELF file tejuwala Linux 1 05-17-2008 08:22 PM
Editing file rahul303 Shell Programming and Scripting 4 09-23-2007 07:49 PM
Editing the File using Awk awk_beginner Shell Programming and Scripting 3 04-06-2007 07:43 AM
Help with editing file dsravan Shell Programming and Scripting 4 01-31-2007 09:59 AM
File editing using awk rinku11 Shell Programming and Scripting 2 11-23-2006 07:34 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-16-2007
Registered User
 

Join Date: Oct 2006
Posts: 12
Editing File using awk/sed

Hello Awk Gurus,

Can anyone of you help me with the below problem. I have got a file having data in below format

pmFaultyTransportBlocks
-----------------------
9842993


pmFrmNoOfDiscRachFrames
-----------------------
NULL


pmNoRecRandomAccSuccess
-----------------------
30646380

I want to format this file into below format so that I can export it to excel using .csv

pmFaultyTransportBlocks,9842993
pmFrmNoOfDiscRachFrames,NULL
pmNoRecRandomAccSuccess,30646380

Thanks in Advance,
Mohammed
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-16-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,485
Code:
awk '{ if( $0 !~ "^-" && length($0) ) { if ( set == 0 ) { printf "%s", $0; set = 1 } else { set = 0; printf ",%s\n", $0 } } }' filename
Reply With Quote
  #3 (permalink)  
Old 05-16-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed -n "/^ *$/!{N;/\n---*$/s//,/;N;s/\n//p;}" file
Reply With Quote
  #4 (permalink)  
Old 05-16-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Code:
nawk 'BEGIN{FS=RS="";OFS=","}{print $1,$3}' myFile
Reply With Quote
  #5 (permalink)  
Old 05-16-2007
Registered User
 

Join Date: Oct 2006
Posts: 12
Thanks vgersh99 your code is working really fine.
Thanks others for also helping me out
Thanks again!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0