Replace space by newline error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace space by newline error
# 8  
Old 09-09-2015
it's do your job ?

Code:
echo ' :20:9400115251184711  :61:1509090908DR991,43NCOL09:04:0032 :86:/OCMT/EUR991,43/PT/FT/BN/ORANGE ESPAGNE S.A.U' | sed 's/[[:space:]]:[0-9][0-9]:/\'$'\n&/g'

This User Gave Thanks to protocomm For This Post:
# 9  
Old 09-09-2015
Hello

This will not work as I need to only modify this for places where I find :61
# 10  
Old 09-09-2015
Thanks !! This will not work as I only need to run this command where I find :61:
# 11  
Old 09-09-2015
Applying your sed script to your sample data on my linux machine yields
Code:
:20:9400115251184711 
:61:1509090908DR991,43NCOL09:04:0032 :86:/OCMT/EUR991,43/PT/FT/BN/ORANGE ESPAGNE S.A.U

, and rightly so. One <newline> is inserted between every :61: and the space in front of it. I can't understand why you expect a <newline> before :86:
This User Gave Thanks to RudiC For This Post:
# 12  
Old 09-10-2015
If you got Perl, please, give it a try:
Code:
 perl -pe 's/(:61:.+?)\s+/\n$1\n/g and s/^\n|(\n)\n/$1/g' file1 > file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Concatenate integer and space/newline for cout in C++

I'm trying to print out integers and space/newline for a nicer output, for example, every 20 integers in a row with ternary operator. In C I could do it with:printf("%d%s",tmp_int, ((j+1)%20) ? "\t":"\n"); but could not figure out the equivalent in C++: cout << ((j+1)%20)?... (4 Replies)
Discussion started by: yifangt
4 Replies

2. UNIX for Dummies Questions & Answers

Replace the unexpected newline char with space in a Fixed width file

Input eg: Ouput Expected. The #rd line had the unexpted new line, which need to be replaced with space. I was planing to go with checking the length of each line using awk and if the length is less than the defeined limit, (12 in above case) will replace the newline with space. ... (5 Replies)
Discussion started by: deepakwins
5 Replies

3. Shell Programming and Scripting

Replace 3rd occurance of SPACE with newline

I have file with SQL output as 0001 firstname1 lastname1 0002 firstname2 lastname2 0003 firstname3 lastname3 0004 firstname4 lastname4 Expected output : 0001 firstname1 lastname1 0002 firstname2 lastname2 0003 firstname3 lastname3 0004 firstname4 lastname4 Let me know if this can... (9 Replies)
Discussion started by: sameermohite
9 Replies

4. Shell Programming and Scripting

Newline to space code removes 0 from the first line

I am having a peculiar problem. First I run the code below to append 0 at the start of each line in some hundreds of files that I have in a directory. These files have each word in a newline. for f in *.dat; do echo "0" > tmpfile cat $f >> tmpfile mv tmpfile $f done Then I run this... (7 Replies)
Discussion started by: shoaibjameel123
7 Replies

5. Shell Programming and Scripting

Replace newline character between a double quotes to a space

Hi Guys, I have a file with content as below aj.txt "Iam allfine" abcdef abcd "all is not well" What I'm trying to say is my data has some new line characters in between quoted text. I must get ride of the newline character that comes in between the quoted text. output must be:... (8 Replies)
Discussion started by: ajahuja
8 Replies

6. UNIX for Dummies Questions & Answers

Remove newline & space

Can someone help me on this. I have a file that has a long line just like below. The long line keeps on being truncated to the next line (new line + space) for some reason. Basically, I just need to remove this problem. Hope somebody can help! Thanks! INPUT FILE: structuralObjectClass:... (4 Replies)
Discussion started by: Orbix
4 Replies

7. Shell Programming and Scripting

Using sed I want to replace space by newline

Input: -------------------------- 123asd 456sdasda 789a ------------------------- output wanted: --------------------- 123asd 456sdasda 789a ---------------------- I want this by sed in simple way please help (I know by: tr ' ' '\n' < inputfile )I want it by sed only (5 Replies)
Discussion started by: RahulJoshi
5 Replies

8. Shell Programming and Scripting

replace >< with > newline <

Hi All, I have the command in PERL for performing this, but Can you please suggest me how can i perform this using AWK: My input xml file looks like this: <aaa>hello</aaa><bbb>hai</bbb> I want the output like this ( means need new line after end of each xml tag): <aaa>hello</aaa>... (1 Reply)
Discussion started by: HemaV
1 Replies

9. Shell Programming and Scripting

Breaking long lines into (characters, newline, space) groups

Hello, I am currently trying to edit an ldif file. The ldif specification states that a newline followed by a space indicates the subsequent line is a continuation of the line. So, in order to search and replace properly and edit the file, I open the file in textwrangler, search for "\r " and... (14 Replies)
Discussion started by: rowie718
14 Replies

10. UNIX for Advanced & Expert Users

newline character, space and tab after a string

no problem (6 Replies)
Discussion started by: angelina
6 Replies
Login or Register to Ask a Question