Add new line after ' char


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add new line after ' char
# 1  
Old 06-20-2012
Add new line after ' char

Hello experts,

I need to convert one file into readable format.

Input file is like following line.

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

Output should be following (After ' char new line char should be added.)

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

Also can I check if file is already in desired format or not. If not then only add new line chars else leave as is.

Please advice.

Regards,

Last edited by Scrutinizer; 06-20-2012 at 12:36 PM.. Reason: code tags
# 2  
Old 06-20-2012
Code:
awk '{$1=$1}1' FS="' " OFS="'\n" yourfile

# 3  
Old 06-20-2012
Code:
awk "{gsub(/' /,RS)}1" file

# 4  
Old 06-21-2012
Quote:
Originally Posted by ctsgnb
Code:
awk '{$1=$1}1' FS="' " OFS="'\n" yourfile

Thanks for your help, this works fine if file is not in proper format. but if it is already in required format , then it again adds new blank line after eachline. like following.

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

Regards

---------- Post updated at 12:42 AM ---------- Previous update was at 12:39 AM ----------

Quote:
Originally Posted by Scrutinizer
Code:
awk "{gsub(/' /,RS)}1" file

Thanks for your reply. This also works fine but it removes ' char at the end of each line. I want this ' char as well.

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

output should be following:
Code:
STG,12345,000,999,'
PQR, 2345,000,999,'
XYZ,7890,000,999,

Please advice.

Regards
# 5  
Old 06-21-2012
Try:
Code:
awk '{gsub(FS,OFS)}1' FS="' " OFS="'\n"

# 6  
Old 06-21-2012
Quote:
Originally Posted by Scrutinizer
Try:
Code:
awk '{gsub(FS,OFS)}1' FS="' " OFS="'\n"

Same issue, its working on non-formated file but if file is already formatted, It adds new line after ' char

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

# 7  
Old 06-21-2012
Modifying ctsgnb's suggestion:
Code:
awk '{sub(/ *$/,x); $1=$1}1' FS="' " OFS="'\n" infile

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