How to add a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add a line
# 1  
Old 10-28-2009
How to add a line

Hi,

Below is the result from my script.... I want to add a line after the time or third line should be empty... Please advise.


Code:
Connected to xrbarb1.xrb.com.
Wed Oct 28 15:15:58 2009^M
Connected to xrbarb2.xrb.com.
Wed Oct 28 15:15:57 2009^M
Connected to xrbcp1.xrb.com.
Wed Oct 28 15:15:58 2009^M
Connected to xrbcp3.xrb.com.
Wed Oct 28 15:15:58 2009^M
Connected to xrbcp4.xrb.com.
Wed Oct 28 15:15:58 2009^M
Connected to xrbcp5.xrb.com.
Wed Oct 28 15:15:59 2009^M
Connected to xrbcp6.xrb.com.
Wed Oct 28 15:16:01 2009^M

But I want to add a line after the time... For example.

Code:
 
Connected to xrbarb1.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbarb2.xrb.com.
Wed Oct 28 15:15:57 2009^M

Connected to xrbcp1.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbcp3.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbcp4.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbcp5.xrb.com.
Wed Oct 28 15:15:59 2009^M

Connected to xrbcp6.xrb.com.
Wed Oct 28 15:16:01 2009^M

# 2  
Old 10-28-2009
Code:
awk 'NR > 1 && NR%2 { print "" }1' file1
Connected to xrbarb1.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbarb2.xrb.com.
Wed Oct 28 15:15:57 2009^M

Connected to xrbcp1.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbcp3.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbcp4.xrb.com.
Wed Oct 28 15:15:58 2009^M

Connected to xrbcp5.xrb.com.
Wed Oct 28 15:15:59 2009^M

Connected to xrbcp6.xrb.com.
Wed Oct 28 15:16:01 2009^M

Or
Code:
awk '1; !(NR%2) { print ""}' file1

(you probably want to lost the ^M characters too - they're a pain!)

Last edited by Scott; 10-28-2009 at 04:49 PM..
# 3  
Old 10-28-2009
Something like that ?
Code:
awk '{sub(/\^M/,RS)}1' file

# 4  
Old 10-28-2009
It's working... Thank you so much. :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

2. Shell Programming and Scripting

How to add the line to previous line in | delimited text?

Hi All, I am new to Unix and I have one challenge and below are the details. I have pipe delimited text file in that data has span into multiple lines instead of single line. Sample data. Data should be like below for entire file. 41|216|398555|77|provided complete NP outcome data ... (21 Replies)
Discussion started by: Narasimhasss
21 Replies

3. Shell Programming and Scripting

How to add line to previous line if not a number?

Hi, I am trying to compare 2 lists. However, one of these lists has to be taken from a.pdf file. When I copy the test into a .txt document there are formatting errors which I need to correct. The document is long (~10,000 lines) so I need to script the re-formatting. Currently my file looks... (9 Replies)
Discussion started by: carlr
9 Replies

4. Shell Programming and Scripting

Choose a line-number to add line

Hello guys, I'm making a script to add visudo with this script. Do you guys know if it's possible to add words to a line-number you want to. Something like this: echo "Adding words to line-number 16" >> /etc/sudoers # (options to add to line-number-16)? Thanks! (3 Replies)
Discussion started by: dannyvdberg
3 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

add number in lines line by line in different files

I have a set of log files that are in the following format ======= set_1 ======== counter : 315 counter2: 204597 counter3: 290582 ======= set_2 ======== counter : 315 counter2: 204597 counter3: 290582 ======= set_3 ======== counter : 315 counter2: 204597 counter3: 290582 Is... (6 Replies)
Discussion started by: grandguest
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. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

9. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

10. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies
Login or Register to Ask a Question