How to handle new line if it is EOL or present as part of string?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to handle new line if it is EOL or present as part of string?
# 1  
Old 07-11-2017
How to handle new line if it is EOL or present as part of string?

Hi All

I am facing some issues while processing a file.
The file has \n as End Of Line. However for some records '\n' is also present as part of string. Hence I am not able to identify proper records from file.
File is # delimited.
Example:
2 rows spread across 4 lines.

Code:
line1: COL1#COL2#[NEWLINE]
line2:LINE WITH "\n" in it.[NEWLINE]
line3:Another line[NEWLINE]
line4:COL1#COL2#COL3[NEWLINE]

When I am reading above file, I am getting 4 rows. However it should be 2 only.
Now I want to process the file so that output looks like
2 rows spread across 2 lines only
Code:
COL1#COL2#LINE WITH "\n" in it.Another line[NEWLINE]
COL1#COL2#COL3[NEWLINE]


Just FYI: COL1,COL2,COL3 are generic and it can be anything. Also, I know in which column new lines may come.

TIA
Nitin
# 2  
Old 07-11-2017
If COL1, COL2,... are anything how can you determine that they make one line?

There must be some thought process you have developed to tell when a \n character is not really the end of the line. Please specify it. Like what defines a column? columns==one word?
columns are delimited by quotes?
# 3  
Old 07-11-2017
Hi Jim

Thanks for quick reply.
I am exporting data from RDBMS table into flat file with FIELDS TERMINATED BY '#' LINES TERMINATED BY '\n'.
However in the file there are few strings which have \n as the value. So a string ideally should be in a single line however it may spread to multiple lines with \n as value inside string.
Eg:
Code:
THIS IS SINGLE LINE STRING

Code:
THIS IS
MULTI-LINE
STRING SEPARATED BY
NEWLINE identifier.

Now the problem is when I m reading data in HIVE, I cannot read this string completely because it encounters \n and truncates string at that point. Remaining string is treated as another line.

is there I way I can handle this situation by processing file. I don't want to export data again from RDBMS to file.

Or in other words how do we process file, when string has delimiter as the genuine value.

Thanks
Nitin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

2. UNIX for Dummies Questions & Answers

How to find a string that is present in the file or not?

Im pretty new to shell scripting, but i have got the jist of it over the past 10 weeks or so i have been using it. I just have one thing im stuck on thats bugging the hell out of me. Here it goes... I need a script that - You enter a filename and then a string which reports whether that string... (2 Replies)
Discussion started by: Waggie14
2 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

5. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

6. Shell Programming and Scripting

~R in between string, how to handle in AWK

Hi, Can any one help how to handle the below situation. Am using Awk script to handle variable When I open the file in VI mode, I see the string as Orange~Rs , but when I cat the file its showing as plain Oranges. When I copied the file over to Windows, am seeing the special character... (3 Replies)
Discussion started by: sp999
3 Replies

7. HP-UX

Utmpd(1M) can't handle records with same line but different ids

For ddfa(7), telnetd(1M) needs to create user accounting database records with the same line (representing the remote side) but different ids (representing the pty that comes to be used for the connection), like line "telnet/ss10" with first id "tb" and then id "tf". Utmpd(1M) cannot handle... (1 Reply)
Discussion started by: madhurtripathi
1 Replies

8. Shell Programming and Scripting

Finding a string in a text file and posting part of the line

What would be the most succinct way of doing this (preferably in 1 line, maybe 2): searching the first 10 characters of every line in a text file for a specific string, and if it was found, print out characters 11-20 of the line on which the string was found. In this case, it's known that there... (13 Replies)
Discussion started by: busdude
13 Replies

9. Shell Programming and Scripting

sort entire line based on part of the string

hey gurus, my-build1-abc my-build10-abc my-build2-abc my-build22-abc my-build3-abc basically i want to numerically sort the entire lines based on the build number. I dont zero pad the numbers because thats "how it is" ;-) sort -n won't work because it starts from the beginning. ... (10 Replies)
Discussion started by: gurpal2000
10 Replies

10. UNIX for Advanced & Expert Users

How to handle backslash in grep string

Hi , I am doing invert grep using -v but the string contain "/" which break the grep command and it do not skip the lines with "/" on it. Diffu.txt ======== 1159c1159 < <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466"> --- > <td... (6 Replies)
Discussion started by: rajbal
6 Replies
Login or Register to Ask a Question