Remove line break at specific position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove line break at specific position
# 1  
Old 08-13-2018
Remove line break at specific position

Hi,

I need to remove line breaks from a file, but only the ones at specific position.

Input file:

Code:
this is ok
this line is divided at posit
ion 30. The same as this one,
also position 30
the rest of lines are ok
with different lengths
The longest ones are always s
plitted at same position

Expected output:

Code:
this is ok
this line is divided at position 30. The same as this one,also position 30
the rest of lines are ok
with different lengths
The longest ones are always splitted at same position

I have tried awk and sed, but I didn't manage to get exactly this behaviour. Could you please help?
# 2  
Old 08-13-2018
Is this a homework assignment?

What are the rules for this?
(Logical intent to remove the characters)

And what have you tried?
# 3  
Old 08-13-2018
Following on from joeyg's comments...

Which OS, which shell, preferred tools and...

What if the line actually contains those 30 characters and is complete, do we look for a '.'?
# 4  
Old 08-13-2018
Hi Joeyg,

It's not a homework. I have a file (more than 450000 lines) where all longest lines were cropped at position 171. I created a short file as an example with lines splitted in two when longer than 30 characters. I need all those lines to be concatenated, and the only way I can imagine is to remove the line break that are in specific position (position 30 in the example) as there are no string in common

------ Post updated at 01:23 PM ------

Hi wisecracker,

Let's suppose that all lines with 30 characters are not complete.

I'm using a unix emulator in windows (cygwin) but I could run it in Solaris if needed.
# 5  
Old 08-13-2018
So every extra CR/LF is at position 30?
Is that what you are looking for some kind of process to strip out - only those at position 30?
# 6  
Old 08-13-2018
That is. I want to remove the CR/LF that are at position 30.
# 7  
Old 08-13-2018
1) What did you try?
2) I can imagine a solution to simply count number of characters in the line. Then if the 30th character if CR to remove it. However, how do you plan to handle lines that SHOULD have the CR at position 30 - some lines may?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Need help on find and replacement on specific line and position

I have a file with 100 lines. On 50 th line , from position 5 to rest of the data , I need to change the occurrence of A to B and Occurrence of M to N. Input file : Line1 Line2 Line3 -- -- 12345ABCDEFM --- -- Line 100 Output Line1 Line2 (40 Replies)
Discussion started by: Rajesh_us
40 Replies

3. UNIX for Dummies Questions & Answers

Remove Line Break VI

I'm trying to make a script that says echo This is the date: I did this echo This is the date: date and it worked. But I need them both on the same line. And putting date on the echo line doesn't work. Is there a way to do so? (1 Reply)
Discussion started by: bbowers
1 Replies

4. Shell Programming and Scripting

break the string and print it in a new line after a specific word

Hi Gurus I am new to this forum.. I am using HP Unix OS. I have one single string in input file as shown below Abc123 | cde | fgh | ghik| lmno | Abc456 |one |two |three | four | Abc789 | five | Six | seven | eight | Abc098 | ........ I want to achive the result in a output file as shown... (3 Replies)
Discussion started by: kannansr621
3 Replies

5. Shell Programming and Scripting

How to remove line break character in a file

Hi, we are trying to process a csv file,in which we are getting data with line breaks.How to remove the line break character in the file? when i try to print the line break charcter using od -c,it gives as '\n' character for both line break and line feed. Please provide your valuable... (6 Replies)
Discussion started by: cnraja
6 Replies

6. Shell Programming and Scripting

Help to remove line break

My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1.Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra... (4 Replies)
Discussion started by: cnraja
4 Replies

7. Shell Programming and Scripting

How to remove line break in a csv file

Hi Experts, My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1, Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra... (6 Replies)
Discussion started by: cnraja
6 Replies

8. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

9. Shell Programming and Scripting

Remove Line Break

Dear all, Please advise what approach can remove all line break from a text file? e.g. Source file: A B C Target file: A, B, C Thanks, Rock (5 Replies)
Discussion started by: Rock
5 Replies
Login or Register to Ask a Question