Remove Line Return from the File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove Line Return from the File
# 8  
Old 04-02-2013
Please use code tags for posting code fragments or data samples.

I do see control characters in your input file and I guess it should be there in last line.
Code:
10014263800000000000000075203130000000000075Y22 ^M$
10010976500000000000009000103130000000590808Y22 ^M$
10010664200000000000007877103130000002462223Y22 ^M$

The dos2unix should remove them!

Run below on command line and check what happens:
Code:
dos2unix XYX20130329164001.txt
awk NF XYX20130329164001.txt

Verify if you are still seeing blank lines.
# 9  
Old 04-02-2013
Code:
cat -Ev XYZ20130329164001.txt
10014263800000000000000075203130000000000075Y22 ^M$
10010976500000000000009000103130000000590808Y22 ^M$
10010664200000000000007877103130000002462223Y22 ^M$

After executing cat -Ev , below is the output
Code:
cat -Ev XYZ20130329164001.txt
10014263800000000000000075203130000000000075Y22 $
10010976500000000000009000103130000000590808Y22 $
10010664200000000000007877103130000002462223Y22 $

After executing awk NF XYZ20130329164001.txt
Code:
10014263800000000000000075203130000000000075Y22 
10010976500000000000009000103130000000590808Y22 
10010664200000000000007877103130000002462223Y22

A blank line is still getting displayed at the end. My requirement is to remove only the last new line that is getting displayed.

Last edited by Scrutinizer; 04-02-2013 at 05:18 PM.. Reason: Changed ICODE tags to CODE tags
# 10  
Old 04-02-2013
That really doesn't make any sense! I do not see any last blank line in your original input file!!

If there is indeed a blank line, you should see something like this:
Code:
$ cat -Ev file
line 1$
line 2$
line 3$
line 4$
$

which is missing in your output that you posted!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove carriage return and append the next line

Hi All, My requirement is to remove the carriage return in from the lines which i am reading if the length is lesser than 1330 and append the next line with it. Below is the realistic example of file structure. Input file: Blah blah blah blah Blah blah blah blah Blah blah blah blah Blah... (16 Replies)
Discussion started by: mad man
16 Replies

2. UNIX for Beginners Questions & Answers

Remove newlines and carriage return from a csv file using UNIX

I need to remove new lines and carriage returns from csv file. Is there anything other than sed and gwak by which we could achieve this ? Any suggestions ? (3 Replies)
Discussion started by: A_Gaddale
3 Replies

3. Shell Programming and Scripting

Need Help to delete carriage return and new line in csv file

Hi All, I have a problem loading the data from a csv file As you see below in the Input ,For the Data starting with " there are 2 lines, which i want to make them into single without changing the format of that data. You can see the desired output below: While i try to open the csv file and... (4 Replies)
Discussion started by: mlavanya
4 Replies

4. Shell Programming and Scripting

SH script to parse string and return multi-line file

Hello all, I have been asked to exercise my shell scripting and it has been 10 plus years since I used to do it so I can not remember hardly anything and ask for your help. What I need to do is copy a line out of a file that can be 10 to 100 characters long, I then need to parse this line into... (3 Replies)
Discussion started by: Alivadoro
3 Replies

5. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

6. Shell Programming and Scripting

Why sed command deletes last line in a file if no carriage return?

Hi I am using sed command to make SCORE=somevalue to SCORE=blank in a file. Please see the attached lastline.txt file. After executing the below command on the file, it removes the last line. cat lastline.txt | sed 's/SCORE=.*$/SCORE=/g' > newfile.txt Why does sed command remove the... (3 Replies)
Discussion started by: ashok.k
3 Replies

7. UNIX for Dummies Questions & Answers

To remove carriage return between the line

Hi, I have a situation where I need to remove the carriage return between the lines. For.eg. The input file: 1,ad,"adc sdfd",edf 2,asd,"def fde",asd The output file should be 1,ad,adc sdfd,edf 2,asd,def fde,asd Thanks Shash (5 Replies)
Discussion started by: shash
5 Replies

8. Shell Programming and Scripting

Remove header(first line) and trailer(last line) in ANY given file

Hi, I need some help in removing the header (first line) and the trailer (last line) in a give file... The data file actually comes in EBCDIC format and I converted it into ASCII.. Now I need to strip off the first line and the last line.. I think we can use sed to do something like this:... (2 Replies)
Discussion started by: madhunk
2 Replies

9. Shell Programming and Scripting

Removing Carriage Return and or line feed from a file

Hello I'm trying to write a shell script which can remove a carriage return and/or line feed from a file, so the resulting file all ends up on one line. So, I begin with a file like this text in file!<CR> line two!<CR> line three!<CR> END!<CR> And I want to end up with a file... (1 Reply)
Discussion started by: tbone231
1 Replies
Login or Register to Ask a Question