Linux Contest with a $25 Amazon Gift Card Giveaway – Week 4
It’s again time for the fourth and final question in the $25 Amazon Gift Card Giveaway. apokalyptik, Ben P., Mahmoud, and Olivers won week 3 by answering our question most accurately. To recap, every week we are asking a Linux question. We want readers to post their answer in the comments section at the bottom of the post. At the end of this week the person who has answered the most questions correctly will win a $25 Amazon Gift card. If there are four different winners each week, a winner within the winners will be chosen at random. If there is a tie, the winner will be determined based on who posted their answers the fastest. Go here for the complete rules.
Question 4 : Week 4
From the command line, how do you remove all the blank lines from example_file1 and output the results into example_file2? Note, you want to preserve example_file1.
The most complete and straightforward answer will win!
Post your answers at the bottom of this post in the comments!
Remember, subscribe to the RSS feed to get notified of the answer. To prevent copying of answers, you will not see any comments until the end of the week.
Popularity: 2% [?]
Filed under: Linux
Like this post? Subscribe to my RSS feed and get loads more!













sed -e ‘/^$/d’ example_file1 > example_file2
sed ‘/^$/d’ FILENAME
sed “/^$/d” example_file1 > example_file2
Apart from an awk script to do the same, i prefer writing one line of bash to do the trick.
input: example_file_1
output: example_file_2
cat example_file_1|while read line;do if [ "$line" != "" ]; then echo "$line"; fi; done>example_file_w
grep -Ev ‘^$’ example_file1 > example_file2
this should do it:
sed ‘/^$/d’ file1 > file2
Hi the answer is:
sed ‘/^$/d’ example_file1 > example_file2
using grep find all lines starting with caracthers “\<w” and redirect the results to example_file2.
grep ‘\ example_file2