How do I append a ^M to the end of each 129 character string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I append a ^M to the end of each 129 character string
# 1  
Old 06-11-2009
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  
Old 06-11-2009
Code:
echo 'A00vswjdv1 Test Junk Junk A00vswjdv2 Test Junk Junk A00vswjdv3 Test Junk Junk' | awk 'gsub("A00", "\n&", $0)'

# 3  
Old 06-11-2009
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  
Old 06-11-2009
Quote:
Originally Posted by Captain
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  
Old 06-11-2009
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  
Old 06-11-2009
Quote:
Originally Posted by Captain
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  
Old 06-13-2009
As this is not related to AIX i transfer it to the "Shell Programming and Scripting" section of the forum.

-push-

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append this string to end of each line

Platform: Solaris 10 I have a file like below $ cat languages.txt Spanish Norwegian English Persian German Portugese Chinese Korean Hindi Malayalam Bengali Italian Greek Arabic I want to append the string " is a great language" at end of each line in this file. (3 Replies)
Discussion started by: omega3
3 Replies

2. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

3. Shell Programming and Scripting

Search for a string, then append character to end of that line only

I have 2 files that I am working with $ cat file1 server1 server3 server5 server6 server8 $ cat file2 server1;Solaris; server2; SLES; server3;Linux; server4; Solaris; server5;SLES; server6;SLES; server7;Solaris; server8;Linux; (1 Reply)
Discussion started by: snoman1
1 Replies

4. Shell Programming and Scripting

append blank spaces at the end of a variable string

Hello, could you please help with this one. I have an input file like this: 123,4567,89000 123456789,9876543,12 and for the output I need strings to be with the fixed length, let's say 15, and if the string is -lt 15 to be populated with blanks at the end until it reach 15, like this: 123 ,4567... (1 Reply)
Discussion started by: apenkov
1 Replies

5. Shell Programming and Scripting

Append char to the end of string from Nth column

I'm sure this is easy to do but I can't find a one line command with awk or sed to append a char to the end of the string from Nth column. Any sugestion please? Thanks (2 Replies)
Discussion started by: cabrao
2 Replies

6. Shell Programming and Scripting

Append the end of each line in a file with a given string

Hi friends, I have a file containing many lines as follows. M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\ADBasicView.java@@\main\v6.4.0_pit_a I would like to append the string "\0" at the end of each line in the file. The output should look... (10 Replies)
Discussion started by: nmattam
10 Replies

7. Shell Programming and Scripting

Append a string at the end of every line in a file

Hi Friends, I have a file with many lines as shown below. /START SAMPLE LINE/ M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\port\Post.java@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\switchview\View.java@@\main\v6.4.0_pit_a /END SAMPLE LINE/ I... (1 Reply)
Discussion started by: nmattam
1 Replies

8. Shell Programming and Scripting

How can I append a string at the end of a line in a file

Hi, guys. I have one question: I have a file called "group", the contents of it is below: ******************************** ... test:x:203: sales:x:204: repair:x:205: research:x:206:brownj ... *********** Now I want to add string ",sherrys" at the end of "research:x:206:brownj", so... (5 Replies)
Discussion started by: daikeyang
5 Replies

9. UNIX for Dummies Questions & Answers

HOWTO Append String to End of Line

I have a comma delimited text file and need to appened ",000000" to the end of every line. For example: Before: "D700000","2006" ,"5000","Open Year" ,"Conversion" ,"Wk64","Productive Payroll $" ,1103.45 After: "D700000","2006" ,"5000","Open Year" ,"Conversion" ,"Wk64","Productive Payroll... (3 Replies)
Discussion started by: bggibson
3 Replies

10. Shell Programming and Scripting

append a character at end of each line of a file

Hi, i want to append a character '|' at end of each line of a file abc.txt. for example if the file abc.txt conatins: a|b|c 1|2|33 w|2|11 i want result file xyz.txt a|b|c| 1|2|33| w|2|11| I know this is simple but sumhow i am not able to reach end of line. its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies
Login or Register to Ask a Question