Any of your options tried does what you want them to do, so I guess your file has some "hidden" features like e.g. non-printing control characters. Try
and post the result.
Please wrap all code, file content, input and output/errors in CODE tags.
It makes it easier to read and preserves multiple spaces for indenting or fixed-width data.
Last edited by rbatte1; 07-24-2017 at 11:18 AM..
Reason: Added CODE tags.
So it is confirmed now that \r carriage characters are present in your Input_file, so could you please first remove them and then try your any of the code mentioned in POST#1 and let us know how it goes then.
Thanks,
R. Singh
You are essentially trying to read from a file, make some changes and write back to it. It doesn't work the way it looks. (*)
A few options are:
1) If your sed version allows it, try the "in-place edit" modifier; something like "sed -i". Check your sed manual "man sed".
2) Use a temporary file as you did for the "tr" command.
======
(*)
As for why it doesn't work the way it looks - you have two different processes (a) a read process and (b) a write process, both sharing the same resource - your file. When they are executed by the OS, a race condition occurs between them which renders the final output unpredictable.
If the writing is done before the reading, you get a zero-byte file. If the writing is done mid-way during the reading process, you may get a "half-baked" output file. The safest way, therefore, is to either use a temporary file explicitly or let sed do it via the "-i" modifier - which is not available in all sed versions.
You could also use other tools - Bash, awk, Perl etc. but the temporary file will be involved, either explicitly or implicitly.
Hi All,
I have a file and I need to delete the lines that are blank and is starting with some characters below. Something like below:
Regular Ascii File:
Line1: AGODA1 BUSAN||SK Lord Beach 4/6/2012 4/7/2012 68060
Line2: AGODA2 BUSAN||SK Beach Hotel 4/6/2012 4/7/2012 610200
Line3: ... (4 Replies)
Hi All,
I have a file.txt which seems like having three lines.
wc -l file.txt
3 file.txt
In fact, once it is open in text editor, this file has four lines where the last line is empty. how can i delete this last empty line of the file.txt? I tried the codes below so far but they... (6 Replies)
Hi,
Consider a file named "testfile"
The contents of file are as below
first line added for test
second line added for test
third line added for test
fourth line added for test
fifth line added for test (5 Replies)
Hi,
I want to use diff to compare two files in a Perl file. But one of the files has some blank lines at the end. So I want to delete the blank lines from the file firstly and then use diff to compare them. But I dont know how to delete the blank lines from the files. Meanwhile, the system is... (5 Replies)
Hi,
I am using BASH. How can I remove any lines in a text file that are either blank or begin with a # (ie. comments)? Thanks in advance.
Mike (3 Replies)
I have a file which contains blocks of text - each block is a multi-lines text delimited by blank lines eg.
<blank line>
several lines of text
...
pattern found on this line
several more lines of text
...
<blank line>
How do you delete the block of text (including the blank lines) when... (17 Replies)
I am attempting to delete blank lines in my file and I've used this command:
sed '/^$/d' $file > $file.fixed
all this seems to do is copy the file and not delete the blank lines located at the end of the file. Any assistance would be greatly appreciated. (3 Replies)
can't figure out a way to delete multiple empty lines but keep single empty lines in a file, file is like this
#cat file
1
2
3
4
5
6
-
What I want is
1
2 (6 Replies)