awk delete blank records


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk delete blank records
# 1  
Old 10-31-2001
awk delete blank records

Hello

I have a file like this...

Name |Sex|Security-Number
abx |F |33787728
cdr |M |823483993
derf |F |

i would like to use awk to delete all records from the file that has a blank in the the 3 rd feild .

the output should be like

Name |Sex|Security-Number
abx |F |33787728
cdr |M |823483993

regards
Hrishy
# 2  
Old 10-31-2001
You can probably safely assume that you only want records that end in a digit (i.e. end in a social security number), so you could use grep:

grep -E '[0-9]$' <filename>

If you really wanted to use awk you could use:

awk -F'|' '{if ($3) print }' <filename>

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find blank records in a file except for few columns

I have a file with the following format: X|High|2|GIC|DM||XHM|||6 Months X|Moderate|2|GIC|DM||XHM|||6 Months X|High|2|GCM|DM||XSF|||6 Months X|Med|2|GCM|DM||XSF|||6 Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th... (10 Replies)
Discussion started by: chatwithsaurav
10 Replies

2. 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

3. Shell Programming and Scripting

Can ksh read records with blank fields

I have a tab delimited file with some fields potentially containing no data. In ksh 'read' though treats multiple tabs as a single delimiter. Is there any way to change that behavior so I could have blank data too? I.e. When encountering 2 tabs it would take it as a null field? Or do I have to... (3 Replies)
Discussion started by: benalt
3 Replies

4. 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

5. Shell Programming and Scripting

Not delete space blank

Hi everyone, i need to "grep" a file with a string with space blanks, like this: grep "XXXX XX" file.txt The problem, i need put the "XXXX XX" in a string variable. When the script executes the grep, do: gresp XXXX XX file.txt How can i solve this problem? The... (5 Replies)
Discussion started by: Xedrox
5 Replies

6. 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

7. Shell Programming and Scripting

How to Delete the First Blank of the First Col?

Hi to all. In the following example, how can I delete the first blank of the first col? (using shell scripting) first second third fourth fifth sixth seventh eighth Thank's for reading. (5 Replies)
Discussion started by: daniel.gbaena
5 Replies

8. Shell Programming and Scripting

Delete last blank line.

I need to delete the last line only if its blank not otherwise. (3 Replies)
Discussion started by: dinjo_jo
3 Replies

9. Shell Programming and Scripting

Why cant i delete blank lines?

I have a sed pipeline: myVar=$(cat $FILE | sed -n '/regex/,/regex/{/regex/d;p}' | sed -n '/regex/!p' | sed -e s/*:// | sed /regex/,+8d \ ) sed '/^$/d' sed '/./!d' And i've tried to add that in a different order rather then just on the end..Why isnt it deleting all the blank... (2 Replies)
Discussion started by: omgsomuchppl
2 Replies

10. UNIX for Dummies Questions & Answers

how to grep for blank records (space,tab,/n)?

I want to exclude (-v) blank records from a file before analysing it. I know I can use '^]$' for spaces and tabs but how do you look for lines that have nothing (/n or line feed) ? (2 Replies)
Discussion started by: Browser_ice
2 Replies
Login or Register to Ask a Question