Adding New empty line in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding New empty line in a file
# 1  
Old 03-13-2011
Adding New empty line in a file

Hi,

I am new to Sed /awk commands. using that i want to add new empty line after every line in a file by leaving first three lines. So, can any one help me out how to achieve this.

Example:
---------
Input Filename: file1.txt

Input Data:
--------Report--------
Date:20-10-03
-----------------------
101,xyz,400
102,abc,500
103,ghj,600
104,gfhj,700

expect results in output file:
--------------------------
Output Filename: fileout.txt

Output file data:
--------Report--------
Date:20-10-03
-----------------------
101,xyz,400

102,abc,500

103,ghj,600

104,gfhj,700

please help me how to achieve this using sed or awk commands. Thanks for your help in advance.

Thanks in advance
G.K
# 2  
Old 03-13-2011
Code:
awk 'NR>3{ORS="\n\n"}1' infile

or
Code:
awk 'NR>3{$0=$0"\n"}1' infile

---------- Post updated at 09:25 PM ---------- Previous update was at 09:24 PM ----------

use
Code:
nawk

instead of
Code:
awk

if you run on solaris plateform

---------- Post updated at 09:48 PM ---------- Previous update was at 09:25 PM ----------

or
Code:
sed '4,${p;s/.*//;}' infile

---------- Post updated at 09:49 PM ---------- Previous update was at 09:48 PM ----------

I tested it on FreeBSD (the last semicolon may be removed depending on what you run)

Last edited by ctsgnb; 03-14-2011 at 05:51 AM..
# 3  
Old 03-13-2011
Code:
 sed -n '4,$G;p;' infile

will do the job.
# 4  
Old 03-13-2011
@sk1418 :

yup ! it does Smilie
# 5  
Old 03-14-2011
Sed command gives the expected results....

Thanks very much to every one for the reply....

Thanks
G.K.K
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete everything after empty line in file

Hello, I am trying to remove everything coming after empty line under ubuntu14.04. How may I do it? file: aaa 020390 bb00id3 c03wisi 209dl x092sia 0290s I expect: aaa 020390 bb00id3 c03wisi (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Adding line in a file using info from previous line

I have a shell script that looks something like the following: mysql -uroot db1 < db1.sql mysql -uroot db2 < db2.sql mysql -uroot db3 < db3.sql mysql -uroot db4 < db4.sql .... different db names in more than 160 lines. I want to run this script with nohup and have a status later. So,... (6 Replies)
Discussion started by: MKH
6 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

How to grep an empty line in a specific column of a file?

Suppose i have the following data : cat file.txt 12431,123334,55353,546646,14342234,4646,35234 123123,3535,123434,132535,1234134,13535,123534 123213,545465,23434,45646,2342345,4656,31243 2355425,2134324,53425,342,35235,23434,234535 3423424,234234,65465,,2344,35436,234524,234... (7 Replies)
Discussion started by: Ravi Tej
7 Replies

5. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

6. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

7. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

8. UNIX for Dummies Questions & Answers

Adding EMPTY columns to Tab-delimited txt file

Hi I have a txt file with 4 columns where I need to add 4 empty columns in the middle meaning that I need what is currently column 4 to be column 8 in a new file. The idea is that I have to use the file as input in a program that reads the data in column 1 and 8, so the content of the other... (8 Replies)
Discussion started by: Banni
8 Replies

9. Shell Programming and Scripting

Checking the Empty line in csv file

Hi all, I have one CSV file(MasterFile.csv) consists of two columns. "./incoming/ABC.CSV","./incoming/ABC_CONTROL.txt" "./incoming/PQR.CSV","./incoming/PQR_CONTROL.txt" "./incoming/123.CSV","./incoming/123_CONTROL.txt" I have written a script to read the MasterFile.csv.Here i want to... (4 Replies)
Discussion started by: sollins
4 Replies

10. Shell Programming and Scripting

printing an empty line in a file (perl)

I know this must be really easy, but i can't get it to work I've got a perl script, with a file. I want to print an empty line, and the following doesn't seem to work: print nameoffile "\n" thanks for your help!! (3 Replies)
Discussion started by: kfad
3 Replies
Login or Register to Ask a Question