Newline characters in fields of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newline characters in fields of a file
# 1  
Old 11-02-2012
Newline characters in fields of a file

My source file is pipe delimeted file with 53 fields.In 33 rd column i am getting mutlple new line characters,dule to that record is breaking into multiple records.
Note : here record delimter also \n

sample Source file with 6 fields :

Code:
1234|abc| \nabcd \n bvd \n cde \n |678|890|900\n

when i am trying to read it, file is reading as
Code:
1234|abc|
abcd
bvd
cde
|678|890|900

required output:
Code:
1234|abc|abcd bvd cde |678|890|900 \n

# 2  
Old 11-02-2012
What you want to achieve with this file..?

And what you have tried so far..?
# 3  
Old 11-02-2012
i am not able to read the file through sequential file in datastage job.
I just wanted to remove new line characters in 3 column of a file.

I am not a unix resource and i am very bad at SED & AWK commands. i am trying to take a help of google
# 4  
Old 11-02-2012
Quote:
Originally Posted by lakshmi001
I just wanted to remove new line characters in 3 column of a file.
If you want to remove "\n" from file use

Code:
sed 's/\\n//g' file

# 5  
Old 11-05-2012
Thankyou for your reply.but this command removes all /n characters in the file. but i need /n character at the end of each record.because it is a record delimiter.
# 6  
Old 11-05-2012
I know there should be better way..

I am not very good at sed regex..Smilie

Code:
sed 's/\\n$/_-_-_/g;s/\\n//g;s/_-_-_/\\n/' file

# 7  
Old 11-05-2012
Try (even though your required output does NOT fit the sample input given):
Code:
awk -F\| '{while (NF<6) {getline Xvar; $0=$0Xvar}}
          1
         ' file
1234|abc| abcd  bvd  cde  |678|890|900

Adapt to your needs, esp. the field separator assignment; works as is on linux/mawk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delimit the fields of a input file which has special characters?

Hi All, I am a newbie to Shell scripting. I have a requirement to Delimit the file fields of a Input file having special characters and spaces with ";". Input File ---------------------------------- Server Port ---------------------------------- Local ... (5 Replies)
Discussion started by: Suganbabu
5 Replies

2. Shell Programming and Scripting

Removing newline characters within DEL quotes.

Hi, Text file has DEL character(ASCII code 127) as quotes with comma as field delimiter. If any of the field contains new line character then I need to remove it. Please help me to achieve this. Thanks Vikram (4 Replies)
Discussion started by: Vikramhm
4 Replies

3. Shell Programming and Scripting

Removinf newline characters in first 62 fields

Hi All, I receive a | delimited text file containing 63 columns. There is no delimiter at the end of the 63rd field, instead there would be a newline character at the end of the text in 63rd column. I wanted to retain this newline character at the end of the 63rd column, as it is desired newline... (1 Reply)
Discussion started by: sagarparadkar
1 Replies

4. Emergency UNIX and Linux Support

How to convert the following characters in some fields in a csv file?

I have a csv file which is produced out of a SED command sed 's/|/","/g; s/^/"/; s/$/"/' A4.txt > A5.csv and I need either an addition to the SED command or a separate command to convert the following characters which occur within the fields in multiple lines 1) "=" to =" and 2)""~ to " (4 Replies)
Discussion started by: etldev
4 Replies

5. Shell Programming and Scripting

Newline between unequal record fields

Assume the following 5 records (field separator is a space): 0903 0903 0910 0910 0910 0910 0910 0910 0917 0917 0917 0917 0924 1001 1001 1001 1001 1008 1008 1008 1008 1015 1015 1015 1015 1022 1029 1029 1029 1029 1105 1105 1105 1105 1112 1112 1112 1112 1119 1126 1126 1126 1126 1203 1203 1203 1203... (8 Replies)
Discussion started by: tree
8 Replies

6. Shell Programming and Scripting

awk puts newline between fields

I have a='123, abc, def, ghi' var1=`echo $a | awk -F", " '{print RS $1}'` echo "something: $var1" which outputs something 123 how can I tell awk not to put a newline between fields? I want it to output: something: 123 (4 Replies)
Discussion started by: unclecameron
4 Replies

7. 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

8. Shell Programming and Scripting

how to keep newline characters in command execution result?

I found that when I used a variable to receive the result from a command execution, the newline characters were removed from the variable. For example, I ran $ ret=`ls -l` $ echo $ret Then, I saw: total 40 -rw-r--r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk -rw-rw-r-- 1 testtrunk... (2 Replies)
Discussion started by: pankai
2 Replies

9. Shell Programming and Scripting

remove trailing newline characters

Hello , I have the folowing scenario : I have a text file as follows : (say name.txt) ABC DEF XYZ And I have one more xml file as follows : (say somexml.xml) <Name>ABC</Name> <Age>12</Age> <Class>D</Class> <Name>XYZ</Name> <Age>12</Age> <Class>D</Class> <Name>DEF</Name>... (7 Replies)
Discussion started by: shweta_d
7 Replies

10. Shell Programming and Scripting

Formatting a text file based on newline and delimiter characters

Hi Everybody, I need some help on formatting the files coming into unix box on the fly. I get a file some thing like this in a single line. ISA^M00^M ^M00^M ^M14^M006929681900 ^M01^M095449419 ... (5 Replies)
Discussion started by: ntekupal
5 Replies
Login or Register to Ask a Question