Editing File using awk/sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editing File using awk/sed
# 1  
Old 05-16-2007
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
# 2  
Old 05-16-2007
Code:
awk '{ if( $0 !~ "^-" && length($0) ) { if ( set == 0 ) { printf "%s", $0; set = 1 } else { set = 0; printf ",%s\n", $0 } } }' filename

# 3  
Old 05-16-2007
Code:
sed -n "/^ *$/!{N;/\n---*$/s//,/;N;s/\n//p;}" file

# 4  
Old 05-16-2007
Code:
nawk 'BEGIN{FS=RS="";OFS=","}{print $1,$3}' myFile

# 5  
Old 05-16-2007
Thanks vgersh99 your code is working really fine.
Thanks others for also helping me out
Thanks again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell quoting problem while editing a remote file using sed

value of i = solarisbox ssh $i "cat /etc/hosts | sed "s/$i\.local\.//" | sed "s/$i\./$i/" | sed "s/$i/$i.sol.com/" > /usr/users/chidori/edit_hosts"While running the above one liner its i am not able to make the changes and write it to the file /usr/users/chidori/edit_hosts . I know there is a... (2 Replies)
Discussion started by: chidori
2 Replies

2. Shell Programming and Scripting

editing file with awk cut and sed

HI All, I am new to unix. I have a file would like to do some editing by using awk, cut and sed. Could anyone help? This file contain 100 lines. There are one line for example: 2,"102343454",5060,"579668","579668","579668","SIP",,,"825922","035885221283026",1,268,"00:59:00.782 APR 17... (2 Replies)
Discussion started by: mimilaw
2 Replies

3. Shell Programming and Scripting

Line/Variable Editing for Awk sed Cut

Hello, i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG: please help a newbie. below is my code: WorkingDir=$1 FileName=`cut -d ',' -f... (2 Replies)
Discussion started by: limamichelle
2 Replies

4. Shell Programming and Scripting

sed or awk editing help

Hi all I use aix (sadly). I've got a file consisting of fields separated by commas, I need a sed or awk command that will delete all spaces between two commas as long as there are only spaces between the commas. eg ,abc, ,sd , ,dr at would become ,abc,,sd ,,dr at I have... (53 Replies)
Discussion started by: mychmose
53 Replies

5. Shell Programming and Scripting

problem in using sed command in editing a file

Hi all, I have a conf file, i want to update some entries in that conf file. Below is the code for that using a temporary file. sed '/workgroup=/ c\workgroup=Workgroup' /usr/local/netx.conf > /usr/local/netx.conf.tmp mv -f /usr/local/netx.conf.tmp /usr/local/netx.conf Sample contents of... (9 Replies)
Discussion started by: ranj14r
9 Replies

6. Homework & Coursework Questions

String editing using sed? awk?

1. The problem statement, all variables and given/known data: Problem Statement for project: When an account is created on the CS Unix network, a public html directory is created in the account's home directory. A default web page is put into that directory. Some users replace or... (13 Replies)
Discussion started by: peage1475
13 Replies

7. UNIX for Dummies Questions & Answers

Pls help me with file editing using awk

Hi all, Pls help me with file editing using awk. I have a text file with the below format. "STANDARD VOLUME ","2009","BUX","V","JCBH49","NF", 001413 "VENDOR MATERIAL-STD ","2009","BUX","V","JCBH49","NF", 009948 "INBOUND TRANS-STD ... (2 Replies)
Discussion started by: srinivas.maddy
2 Replies

8. Shell Programming and Scripting

SED - editing file names (End of line problem?)

For lists in sed, to say what to replace, is this correct: I am hoping that this would recognise that either a "." is present, or that the substitution happens at the end of the line. For files with extensions , my script works perfectly. My problem is, files without extentions, i.e. . ... (1 Reply)
Discussion started by: busillis
1 Replies

9. Shell Programming and Scripting

Editing the File using Awk

I have input file that is having below text 098769 178902 234678 I want to modify the input file like below. '098769', '178902', '234678' Can you please help to get this. I tried but i am not getting this. (3 Replies)
Discussion started by: awk_beginner
3 Replies

10. Shell Programming and Scripting

File editing using awk

Hi All, I have a file, say test.dat which is "|" separated. It has 50K records in it. One of the field in the file has the data in the format 'mm/dd/yyyy'. I need to edit the file by changing the format to 'yyyy/mm/dd' in the same field where as the rest of the data remain untouched. Please... (2 Replies)
Discussion started by: rinku11
2 Replies
Login or Register to Ask a Question