There seems to be a little bit of a language barrier. With this example, I now understand what you were saying in your first message in this thread.
The sed utility (and most editors and text processing utilities meant to run on most UNIX and Linux systems) only have defined behavior when the input file is a text file. In particular sed commands work on input lines. When the input file contains text that is not terminated by a <newline> character (or as you said "doesn't has enter in the end of line"), the input is not a text file because it does not end with a <newline> character. By definition, a line ends with a <newline> character. The sed utility isn't processing the last "row" in your input file because it is not a line. As zaxxon has pointed out, this will work on some systems, but the standards do not require it to work.
On many versions of vi, if you try to edit a file that is missing the terminating <newline> character with the command:
the status line at the bottom of the screen when you open the file will show something like:
meaning it did not find an End-Of-Line character at the end of the file. If you then enter the command :w followed by hitting the Enter (or return or carriage-return) key on your keyboard, vi will then add the missing <newline> character to the end of the file and sed will work as you expect.
If you have a list of files that you know are missing the trailing <newline>, you could also do something like:
where filename1, filename2, and ... are replaced by the names of the files you want to fix. If you give this script the name of a file that already has a <newline> at the end of the file, it will add an empty line to the end of the file.
Hi. I want to be able to update only one line in a file that matches a key using sed, but I can't seem to get this (the key is right at the beginning of each row)
Here is what I have tried so far, but every row is being updated. I want the end result to be that the input file only has the single... (6 Replies)
Hi Friends,
REQUIREMENT: Want to delete files from the current directory match with the same in the file test.txt
set -x
i=1
echo "i=$i"
COUNT=`sed -n '$=' test.txt`
echo "Count=$COUNT"
while
do
"## Here is error##"
FILETOREMOVE=`sed -n \'$i,1p\' test.txt`
echo $FILETOREMOVE... (5 Replies)
I want to use sed command to delete a matched row with a pattern.
And I also want to delete previous and next row of that row.
Which option can I use with sed ? (9 Replies)
I wrote script in bash which generates this report:
phrase1;phrase2;phrase3;phrase4;phrase5;phrase6;phrase7;phrase8
phrase9;phrase2;phrase10;phrase4;phrase11;phrase12;phrase13;phrase14
phrase15;phrase16;phrase17;phrase18;phrase19;phrase20;phrase21;phrase22
...
I would like add name only... (3 Replies)
I have a file with millions of rows that I need to add a delimiter and a new field with a zero to the end of each row. (its too big to open and do a find and replace regex)
I'm looking for the next line '\n' and need to replace it with a Unit Separator (hex \037) 0 \n.
I've tried the... (2 Replies)
Hi,
Tried to look for solution, and found something similar but could not adapt the solution for my needs..
I'm trying to match a pattern (in this case "ProcessType")in a logfile, then delete that line and the 4 following lines.
The logfile looks as follows:
ProcessType: PROCESS_A... (5 Replies)
Hi,
I've got a file with 3 columns which ends like this:
...
1234 345 1400
5287 733 1400
8472 874 1400
9317 726 1400
I want to replace the last row of the last column with the value 0. So my new file will end:
...
1234 345 1400
5287 733 1400
8472 874 1400
9317 726 ... (5 Replies)
Hello ALL,
I have very huge file almost 25G size
contents of the file are "|" delimited columns on each row
eg:
1396745|1078529|KDS|2011-04-21 00:00:00.0|1100|30|2|2011-04-20 22:35:24.0|2011-04-20 22:35:24.0|0|2011-04-21 00:00:00.0|1100|2222434|2011-04-21 11:00:00.0|0|0|2011-06-29... (10 Replies)
Hello,
I want to add a new row to a file to insert data without deleting the previous data there.
Example:
file
a
b
c
d
Output
a
b
newtext
c (6 Replies)
Hi,
Anyone can help on how to re align my data in one row using sed.
test.csv
"url1","abc","project url1"
2016-08-16
"url2,"microsoft","project url2"
2016-08-18
need output like this
"url1","abc","project url1","2016-08-16"
"url2,"microsoft","project url2","2016-08-18"
Thanks in... (8 Replies)