Hi,
I have a file (newfile.txt) with the contents below:
This is a new file. This is a new file. This is a new file. This is a new file.
How could I make a new line of the file as below?
This is a new file.
This is a new file.
This is a new file.
This is a new file.
When there is a keyword "This is" it will be making it a new line.
I know awk can do this, appreciate if anyone can help.
Thanks!
Scott
October 3, 2013, 5:33am
2
Probably not perfect, but:
$ awk '{gsub(/ *This is/, "\nThis is", $0)}1' file
This is a new file.
This is a new file.
This is a new file.
This is a new file.
sea
October 3, 2013, 10:00am
4
sed s/T/\nT/g /path/to/file
Should work but is untested.
Jotne
October 3, 2013, 10:14am
5
This just add "n" before every T, so not working. What if word is starting with Test.
This should not be triggered, only "This is"
sea
October 3, 2013, 10:20am
6
Well actualy, focusing on "This" is wrong either..
So it'll should be better to use any capital letter as indicator for a new line..
As you most surley dont have a file filled with "This is a new line." strings...
sed s/"\.\ "/"\.\n"/g /path/to/file
However, if there is a space after a 'dot', it makes a new linebreak after it while cutting the trailing (1) space.
hth
RudiC
October 3, 2013, 11:58am
7
sed -r 's/\. +([A-Z])/\.\n\1/g' file
Jotne
October 3, 2013, 1:32pm
8
When there is a keyword "This is" it will be making it a new line.
This is some of the request.
sea
October 3, 2013, 1:41pm
9
In that case it should have been posted in Home- & Coursework
To me at least, it very much looks like that under this conditions.
Try:
sed 's/This is/\
&/g; s/^\n//' file
or with seds that can use a \n
in the replacement part:
sed 's/This is/\n&/g; s/^\n//' file
hi,
how should i add an empty line to my file,
example, below myfile.txt
"
this is first line
this is second line
this is third line
"
I would like the file formated as below by adding an empty line to each existing line:
"
this is first line
this is second line
this is third line
"
Thanks
Jotne
October 4, 2013, 6:19am
12
One way: (needs gwak)
awk 1 ORS="\n\n"
this is first line
this is second line
this is third line
Other options
awk '{print $0 "\n"}'
awk '1; { print "" }'
jotne:
One way: (needs gwak)
awk 1 ORS="\n\n"
[..]
[..]
That should work with any awk, not just gawk..
Jotne
October 4, 2013, 7:37am
14
Ahh, thanks. I know there are limitation to number of characters in RS, and thought it was the same for ORS.