The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Break one line to many lines using awk pinnacle Shell Programming and Scripting 16 06-01-2009 03:05 AM
Awk 2 lines to 1 line pinnacle Shell Programming and Scripting 7 04-23-2009 08:51 AM
cat file1 read line-per-line then grep -A 15 lines down in fileb irongeekio Shell Programming and Scripting 6 01-28-2009 06:30 AM
Joining lines in reverse. append line 1 to line 2. dwalley Shell Programming and Scripting 7 08-04-2008 08:11 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2009
javeed7 javeed7 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 34
New line after every 3 lines

Hi all,

My file is of below format:

Code:
abc,111,222,333
xyz,398,399,834
jdj,398,947,487
nmn,535,33,34
sss,43,3,53
ks,343,3,4
d,94,94999

I want to insert 2 rows(NULL,0,0,0) after every 3 lines. shown as below:

o/p:

Code:
abc,111,222,333
xyz,398,399,834
jdj,398,947,487
NULL,0,0,0
NULL,0,0,0
nmn,535,33,34
sss,43,3,53
ks,343,3,4
NULL,0,0,0
NULL,0,0,0
d,94,94999

could anyone help me ?

Use CODE-tags when displaying code, data or logs to enhance readability and to preserve formatting like indention etc., ty.

Last edited by zaxxon; 07-21-2009 at 05:57 AM.. Reason: code tags
  #2 (permalink)  
Old 07-21-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,289

Code:
$> awk 'NR % 3 == 0 {print; print "NULL,0,0,0\nNULL,0,0,0"; next} {print}' infile
abc,111,222,333
xyz,398,399,834
jdj,398,947,487
NULL,0,0,0
NULL,0,0,0
nmn,535,33,34
sss,43,3,53
ks,343,3,4
NULL,0,0,0
NULL,0,0,0
d,94,94999

  #3 (permalink)  
Old 07-21-2009
javeed7 javeed7 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 34
Question

Thanks zaxxon.

A slight change,

My file is of below format:

abc,111,222,333,jjj,22
xyz,398,399,834,ww,33
jdj,398,947,487,eee,44
abc,535,33,34,jjj,22
sss,43,3,53,dd,ter,33
ks,343,3,4,jsj,33
d,94,94999,re,ere
cc,33,53453,xd,22
abx,343,33,jjj,55

As we can see in 5th column, "jjj", the number of rows between two jjj shoud be 7.

the o/p should be as :
abc,111,222,333,jjj,22
xyz,398,399,834,ww,33
jdj,398,947,487,eee,44
NULL,0,0,0,0,0
NULL,0,0,0,0,0
NULL,0,0,0,0,0
NULL,0,0,0,0,0
abc,535,33,34,jjj,22
sss,43,3,53,dd,ter,33
ks,343,3,4,jsj,33
d,94,94999,re,ere
cc,33,53453,xd,22
NULL,0,0,0,0,0
NULL,0,0,0,0,0
abx,343,33,jjj,55

could anyone help me ?
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0