grep to generate a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep to generate a file
# 1  
Old 02-09-2009
grep to generate a file

Hi

I need help with the following problem.

I need to use grep to generate the file text1.txt which is identical to text.txt but contains no blank lines.

I am a complete novice at grep so any help will be great.

Thanks in advance.
# 2  
Old 02-09-2009
Normally I don't answer these threads cause we have so much great talent on the site, but I feel like everyone else is having all the fun Smilie

Code:
grep -v "^ " text.txt > text1.txt

(ok, this is my last one ...)
# 3  
Old 02-09-2009
Can also be done like this:
Code:
grep -v ^$ text.txt > text1.txt

# 4  
Old 02-09-2009
Quote:
Originally Posted by rushhour
Hi

I need help with the following problem.

I need to use grep to generate the file text1.txt which is identical to text.txt but contains no blank lines.

I am a complete novice at grep so any help will be great.

Thanks in advance.
depending on your definition of 'blank lines':
Code:
sed '/^$/d' myFile
nawk 'NF' myFile
grep -v '^$'  myFile

# 5  
Old 02-09-2009
Quote:
Originally Posted by avronius
Can also be done like this:
Code:
grep -v ^$ text.txt > text1.txt

Much better than my incomplete suggestion. Smilie
# 6  
Old 02-09-2009
Quote:
Originally Posted by Neo
Normally I don't answer these threads cause we have so much great talent on the site, but I feel like everyone else is having all the fun Smilie

Code:
grep -v "^ " text.txt > text1.txt

(ok, this is my last one ...)
this will generate lines NOT starting with a 'space' - don't think it's the OPs definition of 'blank lines' Smilie
# 7  
Old 02-09-2009
Quote:
Originally Posted by vgersh99
this will generate lines NOT starting with a 'space' - don't think it's the OPs definition of 'blank lines' Smilie
They were very short blank lines Smilie

We call them "blank stubbies" Smilie Smilie Ha ha
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Maybe a cleaner way to generate a file?

greetings, to be clear, i have a solution but i'm wondering if anyone has a cleaner way to accomplish the following: the variable: LSB_MCPU_HOSTS='t70c7n120 16 t70c7n121 16 t70c7n122 16 t70c7n123 16 t70c7n124 16 t70c7n125 16 t70c7n126 16 t70c7n127 16 t70c7n128 16 t70c7n129 16 t70c7n130 16... (2 Replies)
Discussion started by: crimso
2 Replies

2. Linux

Generate output file

I would like to generate below one line report to output.txt file using csh. 01/01/09 10:15:47|APPL|MD5|ASCII-LF|6480|bal246b61fedf7e07220cedd1a100578 how to make the code to be worked ? Please advise.thanks in advance. #!/bin/csh a = date set s = '|' ... (3 Replies)
Discussion started by: balajikalai
3 Replies

3. Shell Programming and Scripting

Needed script to FTP a File and generate a quality checksum file

hi all i want a script to FTP a file and should generate a quality checksum file means when I FTP a file from one server to another server it should generate a QC file which should contain timestamp,no.of records in that file Thanks in advance saikumar (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

4. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

5. Shell Programming and Scripting

generate a file from existing file based on some rule

Hi guys, i have a file in below format.let me explain first what i am trying to do . i am making a file from this file , will rearrange these columns, then i will run several command(start/stop mentioned in this file) on unix environment. my requirements : 1. i have 27 servers , on each server... (4 Replies)
Discussion started by: deepakiniimt
4 Replies

6. Shell Programming and Scripting

Perl : how to modify a file without generate a temporary file

Hi All, I have a file like below, how can i insert one line after line 1 without using a temporary file in perl? line 1 line 2 line 3 expected result line 1 new line <---insert here line 2 line 3 (2 Replies)
Discussion started by: summer_cherry
2 Replies

7. Programming

Generate XML file from C++

Hi, I need to generate an XML file as output for a C++ program. Immediate idea that came across to me was through fprintf by mentioning all the attribute names/fields in the XML file one by one and inserting the values there which I get from C++ program. Is there any other better way to... (2 Replies)
Discussion started by: debu
2 Replies

8. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

9. UNIX for Dummies Questions & Answers

Script to generate text file from excel file

Hello, I have a excel file which has almost ten columns on the shared drive. I have to write a shell script to ftp that daily to unix server and then extract some columns from there and generate oracle standard text file. The columns should be in proper order and aligned properly, otherwise... (1 Reply)
Discussion started by: isingh786
1 Replies

10. Shell Programming and Scripting

Generate csv file

I have a file which has some thousand records in the following format File: input.txt -> <option value="14333">VISWANADH VELAMURI</option> <option value="17020">VISWANADHA RAMA KRISHNA</option> I want to generate a csv file from the above file as follows File: output.txt -> ... (4 Replies)
Discussion started by: rahulrathod
4 Replies
Login or Register to Ask a Question