Add new line after ' char


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add new line after ' char
# 15  
Old 06-21-2012
Quote:
Originally Posted by Scrutinizer
Yes, but that is the output file isn't it?
If that is the input file then what should the output file look like?
Hi, Input file is following line.

Code:
 
STG,12345,000,999,'PQR, 2345,000,999,'XYZ,7890,000,999,

and required output is

Code:
 
STG,12345,000,999,'
PQR, 2345,000,999,'
XYZ,7890,000,999,

sometimes we do receive files in proper output format. In that case if we execute code then it adds one more line after ' char and file becomes following which is incorrect.

Code:
 
STG,12345,000,999,'
 
PQR, 2345,000,999,'
 
XYZ,7890,000,999,

# 16  
Old 06-21-2012
OK, what I need is if you take for example three lines of such a file in proper output format and run it through od -c
# 17  
Old 06-21-2012
It is quite easy: if an line break follows the single quote the script should leave the single quote alone, otherwise translate it. There is no other possibility to discern between "correct" and "not correct" single quotes (or files containing them).

This means that in the following (constructed) counter-example, any script so far would fail - not because the scripts are wrong, but because you didn't specify exactly enough what you want to have:

Code:
abc'def'ghi
jkl'mno'
pqr

Output according to your rules:

Code:
abc'
def'
ghi
jkl'
mno'

pqr

But what you probably would want to have is a file without the blank line, right?

So, there (enter a literal <ENTER> instead of "^M": in vi, press <CTRL>-<V> in input mode, then hit <ENTER>. You will notice the character look like "^M", but is counted as a single character):

Code:
sed 's/'\(.\)/'^M\1/g' /path/to/input > /path/to/output

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a numeric & special char to end of the first line

Need to add a numeric & special char to end of the first line Existing file: 12-11-16|11 2016 Jan 12:34:55|03:55| 13-10-16|10 2016 Jan 12:34:55|03:55|12-11-16|11 2016 Jan 12:34:55|03:55| 14-10-16|19 2016 Jan 12:34:55|03:55|13-11-16|11 2016 Jan 12:34:55|04:55| 15-10-16|18 2016 Jan... (11 Replies)
Discussion started by: Joselouis
11 Replies

2. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

3. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

4. Shell Programming and Scripting

Add char before certain line

I'm trying to add a '1' before a line that has the word "C_ID" s/.*C_ID.*/&\n1/ The above code did what I need, but the '1' is added after the C_ID word :( Help please. (5 Replies)
Discussion started by: newbeee
5 Replies

5. UNIX Desktop Questions & Answers

add char o end of line if dosent exist

hey , i want to check if the char "#" exist at the end of every line of txt file and if it dosent then add it for example: the cat jumped on my mom # cars can run on water# i cant get a date blue yellow# will be: the cat went back home# cars can run on water# i cant get a... (2 Replies)
Discussion started by: boaz733
2 Replies

6. UNIX for Dummies Questions & Answers

Check if last char in a line is '.' and if not, insert it

Hi all, I've searched for this but couldn't seem to find the answer I'm looking for. I have a text file that looks like this: sgea0447 Earnings followed the same path. earnings followed the same path sgea0448 Economic growth slowed further. economic growth slowed further... (13 Replies)
Discussion started by: pxalpine
13 Replies

7. UNIX for Dummies Questions & Answers

wc -c counts 1 char more per line

Hi, this might be a basic question... why is that wc -c counts 1 more per line than what is there. for example, > cat dum1.txt 123 12 > wc -c dum1.txt 7 dum1.txt Thanks, Sameer. (4 Replies)
Discussion started by: ensameer
4 Replies

8. Shell Programming and Scripting

how first char in odd line and second char in even line

Hi I m having ifconfig -a o/p like sbanlab1:ksh# ifconfig -a | egrep "flags|inet" | awk -F' ' '{print $1,$2}' lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 bge0:... (1 Reply)
Discussion started by: tarunn.dubeyy
1 Replies

9. UNIX for Advanced & Expert Users

Sed - add text to start of line if 1st char anything but space

Problem: I have a lot of files, the files first line should always have 4 spaces before any text. Occasionally some of the files will miss the leading spaces and it's a problem. This is only in the first line. So if there are 4 spaces then text, do nothing. If there are not 4 spaces, add 4... (2 Replies)
Discussion started by: Vryali
2 Replies

10. Shell Programming and Scripting

extraction of last but one char in a line

I need to extract the character before the last "|" in the following lines, which are 'N' and 'U'. The last "|" shouldn't be extracted. Also the no.s of "|" may vary in a line, but I need only the character before the last one. ... (1 Reply)
Discussion started by: hidnana
1 Replies
Login or Register to Ask a Question