replacing blank lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing blank lines
# 1  
Old 10-22-2008
replacing blank lines

Hi i am trying to replace blank lines with a number 0. I tried the following code
awk '{print NF ? $0: blankrow}' blankrow = "0" file1.prg>file2.prg
however i get the following error: fatal: cannot open file `blankrow' for reading (No such file or directory)
file example:
1
2
3

5

6
file output>
1
2
3
0
5
0
6

- thank u
PS i have also tried using echo "file.prg" |sed's!\" "!\"0"!g' -> results with an error -seds!\" "!\"0"!g: command not found

Last edited by rockiefx; 10-22-2008 at 04:55 PM..
# 2  
Old 10-22-2008
Remove the spaces around the = sign:

Code:
awk '{print NF?$0:blankrow}' blankrow=0 file1.prg>file2.prg

# 3  
Old 10-22-2008
tried that.. didnt work
bash: awk{print NF?$1:blankrow}blankrow=0: command not found
# 4  
Old 10-22-2008
Quote:
Originally Posted by rockiefx
tried that.. didnt work
bash: awk{print NF?$1:blankrow}blankrow=0: command not found
And why don't you just copy/paste the command above ...
I'm sure you see that the command you run is different.
# 5  
Old 10-22-2008
lol.. thanks.. worked fine... thanks.. wonders of pasting..
# 6  
Old 10-22-2008
had another concern
in the output file.. if i had to add another field with just tab (blank space every line) would
i just say awk '{print NF?$0:blankrow}' blankrow=0; print " "
or awk '{print NF?$0:blankrow}' blankrow=0; print $0 "\t"
output file example:
1 (tab)
2 (tab)
0 (tab)
3 (tab)
4 (tab)
0 (tab)
# 7  
Old 10-22-2008
Code:
 awk '$0=($0?$0:0)"\t"' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. Shell Programming and Scripting

Reform Lines in File without blank lines and spaces

Hello All, I have a file with data as below. Each line consists of 21 fields. I am not able to load them back to the database. 50733339,"834","834 ","005010X279A1","N","Y","007977163","0001 ",30,"2110D ","EB ","EB007 ","2 ","Conditional Required Data Element Miss ing... (3 Replies)
Discussion started by: Praveenkulkarni
3 Replies

4. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

5. Shell Programming and Scripting

Help in replacing two blank lines with two lines of diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines..... (4 Replies)
Discussion started by: arjun_arippa
4 Replies

6. Shell Programming and Scripting

Help in replacing two blank lines with two diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. Sed "/data/{G;G;}/" filename. In the file, after data tag, two lines got inserted blank lines.. Now... (1 Reply)
Discussion started by: arjun_arippa
1 Replies

7. Shell Programming and Scripting

Delete blank lines, if blank lines are more than one using shell

Hi, Consider a file named "testfile" The contents of file are as below first line added for test second line added for test third line added for test fourth line added for test fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies

8. Shell Programming and Scripting

remove blank lines and merge lines in shell

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

9. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question