76
votes
How to remove empty/blank lines from a file in Unix (including spaces)?
grep
Simple solution is by using grep (GNU or BSD) command as below.
Remove blank lines (not including lines with spaces).
grep . file.txt
Remove completely blank lines (including lines with ...
9
votes
How to remove empty/blank lines from a file in Unix (including spaces)?
To remove empty lines, you could squeeze new line repeats with tr:
cat file.txt | tr -s '\n' '\n'
8
votes
Best way to remove text from the beginning of a huge file
bunzip2 -c backup.sql.bz2 | \
sed -n '/-- Table structure for `mytable`/,$p'
Explanation:
-n suppress automatic printing of pattern space
Address range construction:
Start with regex
/-- Table ...
7
votes
How to decipher Powershell syntax for text formatting?
Select-Object can use a hash table of Header/Values for each item. In this example:
Select-Object Name, @{Name="Size In KB";Expression={ "{0:N0}" -f ($_.Length / 1KB)}} ...
the script is selecting ...
5
votes
How do I grep through binary files that look like text?
You can use these three commands:
grep -a <sth> file.txt
cat -v file.txt | grep <sth>
cat file.txt | tr '[\000-\011\013-\037\177-\377]' '.' | grep <sth>
3
votes
Nginx serves php files as plain text (Mod_Rewrite)
The problem here is that you used an online utility to "convert" from Apache to nginx, and none of these do very well.
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?/$0 break;
}
This needs ...
2
votes
How to decipher Powershell syntax for text formatting?
@{...=...; ...=...} is a hashtable. You may know of them as "dictionaries" in other languages. These are key/value pairs. Semicolons (;) separate the different pairs, and the key and value are ...
2
votes
How to decipher Powershell syntax for text formatting?
I agree with all other answers, the hash-table being a calculated property in this case. I find these one liners wonderful, but they could be presented in a far better way. Technical still a one-liner ...
2
votes
How to decipher Powershell syntax for text formatting?
What you're missing is that @{...} indicates a hashtable array, which are composed of key-value pairs.
As pointed out in the comments, there's a Technet article on this very thing. In your example, ...
2
votes
Best way to remove text from the beginning of a huge file
NOTE: Not an actual answer
Since I was motivated to get this solved now, I went ahead and used grep to find the offset in the file I wanted; it worked great.
Running dd unfortunately requires that you ...
2
votes
Display first few characters of first few lines of a text file
cat /etc/passwd| cut -b -6 will give you the first 6 characters of each line of /etc/passwd file
You may add a | head -9 to read only the first nine lines.
1
vote
Accepted
Risks to increasing the IIS 7 --"Maximum Requesting Entity Body Limit"
Copied from the comment.
Usually the relevant IIS settings are set to prevent common security vulnerabilities.
In your case, if I know your site, and you are using such a setting, I can easily DDOS ...
1
vote
Accepted
Prevent using cleartext passwords in e-mail protocols?
If your Mail provider support it, you should always use the Secured version of the protocols : POPS, IMAPS and SMTPS. All are encrypted and wireshark will not be able to understand anything.
1
vote
Corrupted text file recovery (Win7 x64)
Short answer:
Nope.
Long answer:
Notepad does not operate from the disk. When you open a txt file, it loads the entire file into memory (this is why Notepad is so slow when opening large files, ...
1
vote
How to remove empty/blank lines from a file in Unix (including spaces)?
xargs if you dont mind stripping leading whitespace
$ docker run -it --rm alpine sh
/ # cat <<eof > /tmp/file
> one
>
> two
> three
>
>
> four
> eof
/ # cat /tmp/...
1
vote
How to remove empty/blank lines from a file in Unix (including spaces)?
Ex/Vim
Here is the method using ex editor (part of Vim):
ex -s +'v/\S/d' -cwq test.txt
For multiple files (edit in-place):
ex -s +'bufdo!v/\S/d' -cxa *.txt
Note: The :bufdo command is not POSIX.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
text × 56linux × 11
bash × 6
unix × 5
windows × 4
php × 4
sed × 4
replace × 4
log-files × 3
grep × 3
formatting × 3
ubuntu × 2
centos × 2
active-directory × 2
mysql × 2
group-policy × 2
logging × 2
ftp × 2
command-line-interface × 2
shell × 2
perl × 2
html × 2
export × 2
pipe × 2
binary × 2