-2

my input:

ads bdsd cds dds
ac  cv ss    ds

dsd

output I expect:

ads
bdsd
cds
dds
ac
cv
ss
ds
dsd

command I used:

cat file1.txt | perl -p -i -e 's/\n(.+)/$1/'

but it does not work

oguz ismail
  • 1
  • 16
  • 47
  • 69
Oh God
  • 47
  • 4
  • Perl is decidedly overkill here. The basic problem is that `.+` matches the entire line, including whitespace. You probably meant something like `s/\n?(\S+)\s+/$1\n/g` – tripleee Oct 21 '22 at 11:03
  • Also, the `-i` option makes no sense when the data comes from standard input. – tripleee Oct 21 '22 at 11:04

1 Answers1

0

Try this:

cat file1.txt | tr -s " " "\n"

Basically, it replaces spaces with newlines and removes empty lines.

sudoer
  • 154
  • 7