Skip to main content
Post Closed as "Not suitable for this site" by JRFerguson, pLumo, Stephen Kitt, Panki, waltinator
added 152 characters in body
Source Link
Allexj
  • 265
  • 2
  • 13

I have a file that is like this:

              67 lol
             143 hi
              21 test
               1 ciao
               5 lo

I want to remove the spaces.

67 lol
143 hi
21 test
1 ciao
5 lo

I know that I can use sed to do that, for example with:

cat ciao | sed 's/[[:space:]]*\([[:digit:]]* .*\)/\1/' | sort -g

cat ciao | sed 's/[[:space:]]*\([[:digit:]]* .*\)/\1/' | sort -g

but my professor says that I can easily use cut to do that... but I really don't know how.

Something like this:

cat ciao | rev | cut -d' ' -f1 | rev

would not work because I lose the number information. lol hi test ciao lo

I have a file that is like this:

              67 lol
             143 hi
              21 test
               1 ciao
               5 lo

I want to remove the spaces.

67 lol
143 hi
21 test
1 ciao
5 lo

I know that I can use sed to do that, for example with:

cat ciao | sed 's/[[:space:]]*\([[:digit:]]* .*\)/\1/' | sort -g

but my professor says that I can easily use cut to do that... but I really don't know how.

I have a file that is like this:

              67 lol
             143 hi
              21 test
               1 ciao
               5 lo

I want to remove the spaces.

67 lol
143 hi
21 test
1 ciao
5 lo

I know that I can use sed to do that, for example with:

cat ciao | sed 's/[[:space:]]*\([[:digit:]]* .*\)/\1/' | sort -g

but my professor says that I can easily use cut to do that... but I really don't know how.

Something like this:

cat ciao | rev | cut -d' ' -f1 | rev

would not work because I lose the number information. lol hi test ciao lo

Source Link
Allexj
  • 265
  • 2
  • 13

How to use cut to trim the first x variable spaces

I have a file that is like this:

              67 lol
             143 hi
              21 test
               1 ciao
               5 lo

I want to remove the spaces.

67 lol
143 hi
21 test
1 ciao
5 lo

I know that I can use sed to do that, for example with:

cat ciao | sed 's/[[:space:]]*\([[:digit:]]* .*\)/\1/' | sort -g

but my professor says that I can easily use cut to do that... but I really don't know how.