How to make a new line of the file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make a new line of the file?
# 1  
Old 10-03-2013
How to make a new line of the file?

Hi,

I have a file (newfile.txt) with the contents below:
Code:
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?
Code:
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!

Last edited by Scott; 10-03-2013 at 06:13 AM.. Reason: Code tags
# 2  
Old 10-03-2013
Probably not perfect, but:
Code:
$ 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.

# 3  
Old 10-03-2013
Code:
sed s/T/\nT/g /path/to/file

Should work but is untested.
# 4  
Old 10-03-2013
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"
# 5  
Old 10-03-2013
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...

Code:
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

Last edited by sea; 10-03-2013 at 11:29 AM.. Reason: quotes
# 6  
Old 10-03-2013
Code:
sed -r 's/\. +([A-Z])/\.\n\1/g' file

# 7  
Old 10-03-2013
Code:
When there is a keyword "This is" it will be making it a new line.

This is some of the request.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Make a file accept only two arguments from the command line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) The script is executed in the Korn shell. 2) Name the shell script file is asg6s. 3) The asg6s file is... (7 Replies)
Discussion started by: ProgMan2015
7 Replies

2. Programming

Make a file accept only two arguments from the command line

DELETED (2 Replies)
Discussion started by: ProgMan2015
2 Replies

3. Shell Programming and Scripting

awk - make new line

Hi, I would like to make a new line example like below: "When you post an item you can just delete the files." every 3 words of the above sentence I would like to make a new line like below: " When you post an item you can just delete the files " and after the last line "the... (6 Replies)
Discussion started by: khchong
6 Replies

4. Shell Programming and Scripting

Make Multile line is one line using window Perl

Hi All I have a .csv file which is showing data as ESP Client,ESP Engagement,Misc_Projects_120101,DEFAULT,HA,Unknown,No,Unknown,201704,4.1,Unknown,AAA,Collected-Done,"she,joy.",200111,Unknown,Full Time,,Delivery_DONE AMO,Approved,2012-12-03,2012-12-06,2012-12-06,"Occupied Hours ... (7 Replies)
Discussion started by: adisky123
7 Replies

5. UNIX for Dummies Questions & Answers

search all file for particular text and make changes to line 3

Hi All, I am sitting on HPUX. I want to change the exit into #exit, which appears into 3red line of code in shell scripting, wondering how shell script to be called up to perform action. I have following code in all files. Now, I need to find the text exit and replace into #exit. #!/sbin/sh... (10 Replies)
Discussion started by: alok.behria
10 Replies

6. Shell Programming and Scripting

How to make command line interactive?

I have a file with stats for different month, I use the cat and grep combination to search for different month. cat <file> | grep "April" cat <file> | grep "May" cat <file> | grep "June" etc. How do you make this command interactive. So that I can give the values for the search. Thanks... (7 Replies)
Discussion started by: purelltab
7 Replies

7. Shell Programming and Scripting

Try to make a single line to syslog.

Hi again: Following the thread: https://www.unix.com/shell-programming-scripting/147755-format-lines-file.html I couldn't solve my problem, so I ask you again gurus: I have this code: nohup /usr/sbin/auditstream | /usr/sbin/auditselect -m -e "event== S_ENVIRON_WRITE || event==... (2 Replies)
Discussion started by: iga3725
2 Replies

8. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

make multiple line containing a pattern into single line

I have the following data file. zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii I want to make 2nd field pattern matching multiple lines... (13 Replies)
Discussion started by: VTAWKVT
13 Replies

10. UNIX for Dummies Questions & Answers

How to make all lines into 1 line?

I have a file listing IP addresses, 1 per line, such as: 1.2.3.4 3.4.5.6 12.13.14.15 7.8.9.6 I want all of the entries to be on the same line, and quoted, such as: "1.2.3.4" "3.4.5.6" "12.13.14.15" "7.8.9.6" I got the quotes on there in vi with ":%s/^/"/g" and "%s/$/"/g" ... is there... (8 Replies)
Discussion started by: earnstaf
8 Replies
Login or Register to Ask a Question