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!

file formatting

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
I have a file in this format

column1 column2 column3 column4

Usually I have data like this

column1 column2 column3 column4
xxx yyy zzz aaaaaa bbbbbb cccccccc

i.e column 4 has a long string. But whenever the string gets too large, it breaks like this


column1 column2 column3 column4
xxx yyy zzz aaaaaa bbbbbb cccccccccccccccccccccc
ccccccccc
111 222 333 44444444

Could we format it like?

column1 column2 column3 column4
xxx yyy zzz aaaaaa bbbbbb cccccccccccccccccccccc
ccccccccc
111 222 333 444444

The data is not the same as shown above.
Regards
 
sorry about that it is:

Code:
column1 column2 column3 column4
xxx     yyy     zzz     aaaaaa bbbbbb cccccccccccccccccccccc
                                      ccccccccc
 
Have you tried to play with awk ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Try...
Code:
awk '{
    if(NF>=4){
        print $0
        x=index($0,$6)
    } else {
        printf "%" x-1 "s%s\n", " ", $0
    }
}' infile > outfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top