Contents
Simple SED commands are: sed s/ */ /g This will replace any number of spaces with a single space. sed s/ $// This will replace any single space at the end of the line with nothing. sed s/ /,/g This will replace any single space with a single comma.
How do you replace a space in a new line in Unix?
A few choices:
- The classic, use tr : tr ‘ ‘ ‘n’ < example.
- Use cut cut -d ‘ ‘ –output-delimiter=$’n’ -f 1- example.
- Use sed sed ‘s/ /n/g’ example.
- Use perl perl -pe ‘s/ /n/g’ example.
- Use the shell foo=$(cat example); echo -e ${foo// /\n}
How do I change the space in Linux?
This is how to replace tab by space or replace spaces by tab in linux.
- replace space by tab. in bash you can run. sed -e ‘s/ /t/g’ test.py > test.new.py. in vim you can do this: # first in . …
- replace tab to spaces. set option expandtab (abbreviated to et ) :set et|retab.
31 июл. 2016 г.