0

I have the following file

100843      stars n30   2012-03-08  spartanico83
    stars n50   2009-11-28  babepy
    stars n05   2009-03-09  sandfox
    stars n20   2014-01-17  yeuce

My aim is to have that:

100843      stars n30   2012-03-08  spartanico83
            stars n50   2009-11-28  babepy
            stars n05   2009-03-09  sandfox
            stars n20   2014-01-17  yeuce

I have tried to use column -t as a command line but it gives me that

100843     stars n30   2012-03-08  spartanico83
stars n50  2009-11-28  babepy
stars n05  2009-03-09  sandfox
stars n20  2014-01-17  yeuce

Should I use a combination of awk and sed as well?

Thanks

2
  • 2
    No combination needed, just use awk. Commented May 27, 2014 at 9:44
  • I'm having a look at awk. Commented May 27, 2014 at 9:54

2 Answers 2

2

This can be done just using sed:

sed -r 's/^ +/            /'

If the line begins with spaces, replace the initial spaces with 12 spaces.

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, Jotne. It seems the copy and paste from my file to stackoverflow dashboard changed something ... If I'm pasting the content of my file in my cygwin env, Barmar's solution is working a treat. Apologies, Barmar.
0

Put a tab with sed:

sed 's/^\([ ]*stars\)/\t\1/' input

or use sed/column for a more robust solution:

sed 's/^\([ \t]*stars\)/@\1/' input | column -t | sed 's/^@/ /'

2 Comments

However, is there nothing simplier? I'm asking because I truly thought that dealing with the options of column would be enough.
There might be something simpler but column seems to ignore the leading whitespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.