$
$
$ # Show data without line numbers on the left
$ cat f13
0 2.14014e-07
13.214 1.00771e-06
13.947 3.76252e-05
13.958 5.2692e-06
13.966 4.87701e-06
14.065 3.81149e-06
14.076 3.65411e-06
14.29 9.82566e-07
17.899 6.10872e-07
19.757 7.14666e-07
200.947 1.78718e-07
226.555 1.34066e-07
231.43 1.35589e-07
231.8 9.41089e-08
266.201 1.91486e-07
$
$ # Show data *with* lines numbers on the left
$ cat -n f13
1 0 2.14014e-07
2 13.214 1.00771e-06
3 13.947 3.76252e-05
4 13.958 5.2692e-06
5 13.966 4.87701e-06
6 14.065 3.81149e-06
7 14.076 3.65411e-06
8 14.29 9.82566e-07
9 17.899 6.10872e-07
10 19.757 7.14666e-07
11 200.947 1.78718e-07
12 226.555 1.34066e-07
13 231.43 1.35589e-07
14 231.8 9.41089e-08
15 266.201 1.91486e-07
16
$
$ # Remove the blank line at the end. Assume that the blank line *may have* whitespaces.
$ # Perform an inline replacement in the data file.
$
$ perl -pi.bak -e 's/^\s*$//' f13
$
$ # Check the modified data file.
$ cat -n f13
1 0 2.14014e-07
2 13.214 1.00771e-06
3 13.947 3.76252e-05
4 13.958 5.2692e-06
5 13.966 4.87701e-06
6 14.065 3.81149e-06
7 14.076 3.65411e-06
8 14.29 9.82566e-07
9 17.899 6.10872e-07
10 19.757 7.14666e-07
11 200.947 1.78718e-07
12 226.555 1.34066e-07
13 231.43 1.35589e-07
14 231.8 9.41089e-08
15 266.201 1.91486e-07
$
$ # Check the backup data file generated by the Perl one-liner.
$ cat -n f13.bak
1 0 2.14014e-07
2 13.214 1.00771e-06
3 13.947 3.76252e-05
4 13.958 5.2692e-06
5 13.966 4.87701e-06
6 14.065 3.81149e-06
7 14.076 3.65411e-06
8 14.29 9.82566e-07
9 17.899 6.10872e-07
10 19.757 7.14666e-07
11 200.947 1.78718e-07
12 226.555 1.34066e-07
13 231.43 1.35589e-07
14 231.8 9.41089e-08
15 266.201 1.91486e-07
16
$
$
$
This should work if:
(a) there is more than one blank line at the end of the file => the one-liner removes all those blank lines at eof
(b) there is one or more than one blank line before the end of the file => the one-liner removes all those blank lines wherever they are before eof
(c) the lines refered to in (a) and (b) have zero or more whitespaces
tyler_durden
Last edited by durden_tyler; 09-09-2010 at 02:19 PM..
Is there any way to delete the Junk Characters(Invalid Characters like ^,',",),(,&,# etc.,) at the end of each record in a file?
I want to do this using a single line script.
Thanks to all in advance!!! (5 Replies)
Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Hi All
i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out?
Kind regards
Brian (4 Replies)
Hi Guys,
I have a quetion which was already discussed in the forum, but for some reason all approches suggested fail for me.
I have a file which have blank lines at the body of the text as well as at the end. I need to delete ONLY blank lines at the end. Unfortunatly the approach below does not... (5 Replies)
here is the contents of bigfile.sql
CREATE TABLE `Table11` (
`id` int(11) NOT NULL ,
`entityName` enum('Lines','EndUsers') COLLATE utf8_unicode_ci NOT NULL,
`parentAllianceMigrationProjectId` varchar(255) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8... (30 Replies)
Discussion started by: vivek d r
30 Replies
LEARN ABOUT LINUX
git-stripspace
GIT-STRIPSPACE(1) Git Manual GIT-STRIPSPACE(1)NAME
git-stripspace - Remove unnecessary whitespace
SYNOPSIS
git stripspace [-s | --strip-comments] < input
DESCRIPTION
Clean the input in the manner used by Git for text such as commit messages, notes, tags and branch descriptions.
With no arguments, this will:
o remove trailing whitespace from all lines
o collapse multiple consecutive empty lines into one empty line
o remove empty lines from the beginning and end of the input
o add a missing
to the last line if necessary.
In the case where the input consists entirely of whitespace characters, no output will be produced.
NOTE: This is intended for cleaning metadata, prefer the --whitespace=fix mode of git-apply(1) for correcting whitespace of patches or
files in the repository.
OPTIONS -s, --strip-comments
Skip and remove all lines starting with comment character (default #).
-c, --comment-lines
Prepend comment character and blank to each line. Lines will automatically be terminated with a newline. On empty lines, only the
comment character will be prepended.
EXAMPLES
Given the following noisy input with $ indicating the end of a line:
|A brief introduction $
| $
|$
|A new paragraph$
|# with a commented-out line $
|explaining lots of stuff.$
|$
|# An old paragraph, also commented-out. $
| $
|The end.$
| $
Use git stripspace with no arguments to obtain:
|A brief introduction$
|$
|A new paragraph$
|# with a commented-out line$
|explaining lots of stuff.$
|$
|# An old paragraph, also commented-out.$
|$
|The end.$
Use git stripspace --strip-comments to obtain:
|A brief introduction$
|$
|A new paragraph$
|explaining lots of stuff.$
|$
|The end.$
GIT
Part of the git(1) suite
Git 1.8.5.3 01/14/2014 GIT-STRIPSPACE(1)