06-17-2010
Remove blank lines and comments from text file
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
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi all,
I use translate web to get subtitle file in my langues . But in output file have bad blank lines .
I need scrip (i use debian ) to remove this blank lines .
szintax of my bad *.srt file :
------
number
blank1
number:number ---> number:number
blank2
text1
.
textn
blankS... (10 Replies)
Discussion started by: hungbp
10 Replies
2. Shell Programming and Scripting
Hi,
I have this problem that there are blank spaces in my text file... i want to remove them
line 1
line 2
line 3
I want to remove the space between line 2 and line 3... I tried sed... it work but it prints the whole text file at the command prompt which i dont want....
sde i tried was... (4 Replies)
Discussion started by: bhagya2340
4 Replies
3. Shell Programming and Scripting
Hi Guys,
I have been trying to remove blank lines from a file with no success. I tried using all the following options on the file:
tr -s '\n' < abc.txt
grep -v "^$" abc.txt
sed '/^$/d' abc.txt
sed '/./!d' abc.txt
awk '/./' abc.txt
The file is a text file. (11 Replies)
Discussion started by: npatwardhan
11 Replies
4. Shell Programming and Scripting
Hi,
I'm not a expert in shell programming, so i've come here to take help from u gurus.
I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command.
I've a datatable csv of the below format -
--in file format
xx,xx,xx ,xx , , , , ,,xx,
xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies
5. Shell Programming and Scripting
I have a text file which has blank lines. I want them to be removed before upload it to DB using SQL *Loader. Below is the command line, i use to remove blank lines.
sed '/^ *$/d' /loc/test.txt
If i use the below command to replace the file after removing the blank lines, it replace the... (6 Replies)
Discussion started by: vel4ever
6 Replies
6. Shell Programming and Scripting
Hello,
I have some data in a text file where fields are separated by blank lines. There are only 6 fields however some fields have several lines of data as I will explain. Also data in a particular field is not consistently the same size but does end on a blank line. The first field start with... (6 Replies)
Discussion started by: vestport
6 Replies
7. Shell Programming and Scripting
Hi All,
I am creating a text file using perl. The first record I am writing as "$line" and all the other as "\n$line". At the end the file is having N number of lines. I am using this file for MLOAD (Teradata), which is reading N+1 lines in the file and failing.I am not able to find new line... (2 Replies)
Discussion started by: unankix
2 Replies
8. Shell Programming and Scripting
Hello,
I have some tab delimited files that may contain blank columns. I would like to delete the blank columns if they exist. There is no clear pattern for when a blank occurs.
I was thinking of using sed to replace instances of double tab with blank,
sed 's/\t\t//g'
All of the examples... (2 Replies)
Discussion started by: LMHmedchem
2 Replies
9. Shell Programming and Scripting
Hi , We need to remove comment like pattern from a code text. The possible comment expressions are as follows.
Input
BizComment : Special/*@
Name:bzt_53_3aea640a_51783afa_5d64_0
BizHidden:true
@*/
/* lookup Disease
Category Therapuetic Class */
a=b;... (6 Replies)
Discussion started by: VikashKumar
6 Replies
10. Shell Programming and Scripting
Hi,
I tried the following options but was unable to delete blank lines from file
Input file = temp.hash.txt
temp.hash.txt content
90
0
89.56
0
0
57575.4544
56.89 (9 Replies)
Discussion started by: uuuunnnn
9 Replies
LEARN ABOUT MOJAVE
git-stripspace
GIT-STRIPSPACE(1) Git Manual GIT-STRIPSPACE(1)
NAME
git-stripspace - Remove unnecessary whitespace
SYNOPSIS
git stripspace [-s | --strip-comments]
git stripspace [-c | --comment-lines]
DESCRIPTION
Read text, such as commit messages, notes, tags and branch descriptions, from the standard input and clean it in the manner used by Git.
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 2.17.1 10/05/2018 GIT-STRIPSPACE(1)