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
Search a string and append text after the string kesu2k Shell Programming and Scripting 8 07-18-2008 08:35 PM
Sed append newline character Gaurang033 Shell Programming and Scripting 3 06-26-2008 06:57 AM
append a character at end of each line of a file muaz Shell Programming and Scripting 4 06-25-2008 08:48 AM
append character to a file enuenu High Level Programming 3 06-11-2007 05:59 AM
Using SED to append character to each line c0nn0r Shell Programming and Scripting 4 07-08-2006 10:07 PM

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 06-11-2009
Captain Captain is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
How do I append a ^M to the end of each 129 character string

Hello all,
I have a stumper of a problem. I am trying to append a ^M or "newline" to the end of each 129 character string in a huge file in unix.

Each string starts with A00.

I am trying to get the file to go from...
A00vswjdv1 Test Junk Junk A00vswjdv2 Test Junk Junk A00vswjdv3 Test Junk Junk

to look like....
A00vswjdv1 Test Junk Junk
A00vswjdv2 Test Junk Junk
A00vswjdv3 Test Junk Junk

Any help is greatly appreciated.

BTW. I am on a AIX box.
  #2 (permalink)  
Old 06-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo 'A00vswjdv1 Test Junk Junk A00vswjdv2 Test Junk Junk A00vswjdv3 Test Junk Junk' | awk 'gsub("A00", "\n&", $0)'

  #3 (permalink)  
Old 06-11-2009
Captain Captain is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
I apologize, the file is actually very long (Over 50MB). My example only showed a string of 3. The entire file is 1 long string going on for many occurances of the "A00...." data string.
  #4 (permalink)  
Old 06-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by Captain View Post
I apologize, the file is actually very long (Over 50MB). My example only showed a string of 3. The entire file is 1 long string going on for many occurances of the "A00...." data string.
The original post was intended as a hint.

Code:
awk 'gsub("A00", "\n&", $0)' myFile

YMMV depending on the your awk implementation.
  #5 (permalink)  
Old 06-11-2009
Captain Captain is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Thank you. I will try it now and post again if it works.

-----Post Update-----

Command finished but I now find the strings do not all start with A00. They range from A00-A55.
The command did work for the A00 ones.

What a mess!

Last edited by Captain; 06-11-2009 at 04:05 PM..
  #6 (permalink)  
Old 06-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by Captain View Post
Thank you. I will try it now and post again if it works.

-----Post Update-----

Command finished but I now find the strings do not all start with A00. They range from A00-A55.
The command did work for the A00 ones.

What a mess!
well...... you didn't say you had different strings signifying the start - GIGO

Code:
awk 'gsub("A[0-5][0-5]", "\n&", $0)' myFile

  #7 (permalink)  
Old 06-13-2009
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,640
As this is not related to AIX i transfer it to the "Shell Programming and Scripting" section of the forum.

-push-

bakunin
Reply

Bookmarks

Tags
append, newline after number of characters

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 07:09 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