User Tools

Site Tools


ubuntu:file:delete_empty_lines

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
ubuntu:file:delete_empty_lines [2020/07/15 09:30] – external edit 127.0.0.1ubuntu:file:delete_empty_lines [2022/06/13 10:29] (current) – removed peter
Line 1: Line 1:
-====== Ubuntu - File - Delete empty lines ====== 
- 
-===== Using awk ===== 
- 
-<code bash> 
-awk 'NF' my_input > my_output 
-</code> 
- 
----- 
- 
-===== Using sed ===== 
- 
-Delete empty lines using sed. 
- 
-<code bash> 
-sed '/^$/d' <input-file> 
-echo "LINE" | sed '/^$/d' 
-echo "$VAR" | sed '/^$/d' 
-sed '/^[[:space:]]*$/d' input_file 
- 
-sed '/^$/d' input > output 
-sed '/^\s*$/d' in > out 
-sed -n '/^\s*$/!p' in.txt > out.txt 
-sed '/^[[:space:]]*$/d' input > output 
-</code> 
- 
----- 
- 
-===== Examples ===== 
- 
- 
-==== Delete all empty lines from a file ==== 
- 
-<code bash> 
-sed '/^$/d' /tmp/data.txt 
-</code> 
- 
----- 
- 
-==== Store output to another file use redirection operator ==== 
- 
-<code bash> 
-sed '/^$/d' /tmp/data.txt > /tmp/output.txt 
-</code> 
- 
----- 
- 
-==== Update the file directly ==== 
- 
-<code bash> 
-sed -i '/^$/d' /tmp/data.txt  
-</code> 
  
ubuntu/file/delete_empty_lines.1594805433.txt.gz · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki