Perl/awk/sed Program to convert rows to columns between identifiers -


my input file format:

.set abc col2=123 col3=xyz col4=bcd col5=efg  .set prs col3=456 col5=kda 

my output format:

abc~123~xyz~bcd~efg prs~~456~~kda 

thanks

using awk

awk '{printf (/^\.set/?rs:"~")"%s",$0} end {print ""}' file  .set abc~col2=123~col3=xyz .set prs~col2=456~col3=kda 

if blank line @ top of output problem, do:

awk 'nr>1{printf "%s"(/^\.set/?rs:"~"),a} {a=$0} end {print a}' file .set abc~col2=123~col3=xyz .set prs~col2=456~col3=kda 

/^\.set/ line start .set?
?rs yes, use rs new line
:"~" no, use~` field separator.

so test in formatting see if should use newline or ~


updated correct result after op change requested output.

awk -f= 'nr>1{printf "%s"(/^\.set/?rs:"~"),a} {a=/^\.set/?$0:$2} end {print a}' file .set abc~123~xyz .set prs~456~kda 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -