Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comma delimit & join lines 2

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
Struggling to format the following

Code:
     Field 1               Field 2              Field 3
|-----------------|  |--------------------| |-------------|
                               Field 3
                 |----------------------------------------|
                           Field 3
     |----------------------------------------------------|

01/21/2007 22:44:45   servername subserver   dfdddfdfdfdfdf
                  dfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd
      dfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd

I'm trying to get each record on one line and delimit each field with {

running this twice joins the lines

awk '/^[0-9]/{printf ("%s",$0);next}
1 < /tmp/input > output1

then try sed to remove spaces. Anyone got a tidy way?





Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Also after further testing my awk statement isn't working correctly

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
A starting point:
awk '/^[0-9]/{if(NR>1)printf "\n"}{sub(/^[ \t]+/,"");printf "%s",$0}END{printf "\n"}' /tmp/input > output1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Spot on as usual, could you break down whats happening. I seem to ask a question like this every six months. I have the awk programming language book but the info isn't sticking.



Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Code:
awk '
    # for each line of input beginning with a timestamp, print  
    # a line feed
    /^[0-9]/{if(NR>1)printf "\n"}
    # for every line of input, substitute all sequences of 
    # spaces and tabs with a comma, then print out the line 
    # (with no line feed)
    {sub(/^[ \t]+/,"");printf "%s",$0}
    # print out the final line feed after all input has been
    # processed
    END{printf "\n"}
' /tmp/input > output1

Annihilannic.
 
Sorry first comment should read "for each line of input beginning with a timestamp, except the first, print a line feed".

Annihilannic.
 
Thanks

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top