Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file in Unix like below (test.txt):

20130912-02:29:03 BT_TBL CISCUST BT_TBL_CISCUST_003015.dat
20130912-05:00:04 BT_TBL TMVLP BT_TBL_TMVLP_001026.dat
20130912-08:26:20 D_SNODE CPR8S D_SNODE_CPR8S_001772.dat
20130912-12:15:37 BT_PRA EWSDCAI BT_PRA_EWSDCAI_193228.dat
20130912-12:15:03 AMSD TTFILE AMSD_TTFILE_285130.dat
20130912-12:10:02 SIN2TTFILE SIN2_TTFILE_131635.dat
20130912-12:15:16 BT_ONEI NOAS_AM BT_ONEI_NOAS_AM_032902.dat

I need the columns to have a fixed length though, like so. They should be separated by tabs:

20130912-02:29:03   BT_TBL    CISCUST   BT_TBL_CISCUST_003015.dat
20130912-02:30:05   BT_TBL    CISTERM   BT_TBL_CISTERM_003034.dat
20130912-05:00:04   BT_TBL    CTVLP     BT_TBL_CTVLP_001005.dat
20130912-05:00:04   BT_TBL    TMVLP     BT_TBL_TMVLP_001026.dat
20130912-08:26:20   D_SNODE   CPR8S     D_SNODE_CPR8S_001772.dat
20130912-08:20:07   D_SNODE   CPR9S     D_SNODE_CPR9S_001692.dat
20130912-08:20:08   D_SNODE   SUB9S     D_SNODE_SUB9S_001691.dat
20130912-12:15:37   BT_PRA    EWSDCAI   BT_PRA_EWSDCAI_193228.dat
20130912-12:15:03   AMSD      TTFILE    AMSD_TTFILE_285130.dat
20130912-12:20:02   DLLS      TTFILE    DLLS_TTFILE_137361.dat
20130912-12:20:02   LOGS      TTFILE    LOGS_TTFILE_150352.dat
20130912-12:10:02   SIN2      TTFILE    SIN2_TTFILE_131635.dat
20130912-12:15:16   BT_ONEI   NOAS_AM   BT_ONEI_NOAS_AM_032902.dat
20130912-12:10:25   BT_ONEI   NOAS_FF   BT_ONEI_NOAS_FF_030531.dat
20130912-12:21:01   BT_IN     AMSSC11   BT_IN_AMSSC11_565012.dat
20130912-12:22:01   BT_IN     AMSSC12   BT_IN_AMSSC12_571777.dat
20130912-12:21:32   BT_IN     FFTSC11   BT_IN_FFTSC11_580199.dat
20130912-12:22:31   BT_IN     FFTSC12   BT_IN_FFTSC12_576488.dat
20130912-12:22:02   AMSD      VP_IN     AMSD_VP_IN_770412.dat
20130912-12:24:01   DLLS      VP_IN     DLLS_VP_IN_412252.dat
20130912-12:23:02   LOGS      VP_IN     LOGS_VP_IN_440553.dat
20130912-12:20:03   SIN2      VP_IN     SIN2_VP_IN_395060.dat

How can I do that?

share|improve this question
    
This file looks like it's an output of a script. Maybe it would be easier to fix a script that generates it, than fixing the output itself? –  Vladimir Tsuverkalov Sep 12 '13 at 12:58
    
Next time please take care of your formatting by looking at the preview of your question. Thanks. –  slhck Sep 12 '13 at 13:00
    
What about sed -i 's/ */\t/' file ? –  Kwaio Sep 12 '13 at 13:46
1  
Why did you tag the question with microsoft-excel? –  Jerry Sep 12 '13 at 14:58

2 Answers 2

With GNU sed, replace every space with a tab, globally:

sed 's/ /\t/g' test.txt > new.txt

Since you mentioned Unix, you might be interested in BSD sed, which does not understand the \t. Here, enter:

sed 's/ /Ctrl-VTab/g' test.txt > new.txt

Pressing Ctrl-V will take the next pressed key and insert it literally.

share|improve this answer

In a text editor, replace spaces with tabs using the find and replace tool.

share|improve this answer
    
Care to explain how? As it is this answer is almost, but not quite, entirely unhelpful. –  Mokubai Sep 12 '13 at 16:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.