How to grep an empty line in a specific column of a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep an empty line in a specific column of a file?
# 1  
Old 01-08-2013
How to grep an empty line in a specific column of a file?

Suppose i have the following data :

cat file.txt

Code:
12431,123334,55353,546646,14342234,4646,35234
123123,3535,123434,132535,1234134,13535,123534
123213,545465,23434,45646,2342345,4656,31243
2355425,2134324,53425,342,35235,23434,234535
3423424,234234,65465,,2344,35436,234524,234
2345235,343224,234234,,234234,646,2342,2354
324234,6456,23424,,45645,234,234,246545,234
342334,234545,234,,2342,4354,2344,235235,2344

please suggest the below question :

1 . I want only those rows in which the fourth column is empty .

*********
it should generate the last four lines
*********

Last edited by Scrutinizer; 01-08-2013 at 03:14 AM..
# 2  
Old 01-08-2013
Code:
 
awk -F, '$4==""' input.txt

# 3  
Old 01-09-2013
Grep all the rows that has a particular column (with heading) empty

Code:
A,B,C,D,E,F,G
12431,123334,55353,546646,14342234,4646,35234
123123,3535,123434,132535,1234134,13535,123534
123213,545465,23434,45646,2342345,4656,31243
2355425,2134324,53425,342,35235,23434,234535
3423424,234234,65465,,2344,35436,234524,234
2345235,343224,234234,,234234,646,2342,2354
324234,6456,23424,,45645,234,234,246545,234
342334,234545,234,,2342,4354,2344,235235,2344

Suppose the columns have headings A,B,C,D,E,F,G . I want to grep all the rows in column D which is empty .
This should generate last 4 lines .

Last edited by Scrutinizer; 01-09-2013 at 03:29 AM.. Reason: code tags
# 4  
Old 01-09-2013
did u try my awk command ?
# 5  
Old 01-09-2013
Yes , It helped but in another file there headings for each column name .
I need to select the rows of a particular column like say column D here and under them empty columns .
# 6  
Old 01-09-2013
simple grep would solve your question

Code:
/users/oracle> cat a.txt
12431,123334,55353,546646,14342234,4646,35234
123123,3535,123434,132535,1234134,13535,123534
123213,545465,23434,45646,2342345,4656,31243
2355425,2134324,53425,342,35235,23434,234535
3423424,234234,65465,,2344,35436,234524,234
2345235,343224,234234,,234234,646,2342,2354
324234,6456,23424,,45645,234,234,246545,234
342334,234545,234,,2342,4354,2344,235235,2344
/users/oracle > cat a.txt|grep ",,"
3423424,234234,65465,,2344,35436,234524,234
2345235,343224,234234,,234234,646,2342,2354
324234,6456,23424,,45645,234,234,246545,234
342334,234545,234,,2342,4354,2344,235235,2344
/users/oracle >


Last edited by Scrutinizer; 01-09-2013 at 03:30 AM.. Reason: code tags
# 7  
Old 01-09-2013
post your code using code tag button.

post the input and expected output

using the code tag button in the editor below (hint: it looks like this --> Image)

https://www.unix.com/how-post-unix-li...code-tags.html
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

2. Shell Programming and Scripting

How to read particular line in file from specific column?

Hi...friends.... I want to create inventory...information for that I need to read some specific row say 2nd row from 1st 3 column and and write data with particular file used, I have some more column also but I need only 3 column data of first entry after header I attached sample file..those... (12 Replies)
Discussion started by: nex_asp
12 Replies

3. UNIX for Dummies Questions & Answers

Grep from specific column in one file based on another file [Please help!]

Hey Guys, to keep it simple, I have an idFile: 1006006 1006008 1006011 1007002 ...... and famFile: 1006 1006001 1006016 1006017 1 1006 1006006 1006016 1006017 1 1006 1006007 0 0 2 1006 1006008 1006007 1006006 2 1006 1006010 1006016 1006017 2 1006 1006011 1006016 1006017 1 1006... (2 Replies)
Discussion started by: Zoho
2 Replies

4. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

5. Shell Programming and Scripting

delete empty spaces at specific column

Hi All, If anybody could help me with my scenario here. I have a statement file. Example of some content: DATE DESC Debit Credit Total Rate 02-Jan-08 Lodgement 200.00 1200.00 2.51 14-Sep-07 Withdrawal 50.00 1000.00 ... (8 Replies)
Discussion started by: yonez
8 Replies

6. Shell Programming and Scripting

grep a specific line from a file

Is there a way to grep only one line from a file listing name of files? If I use head -1 it's ok(the first line only) If I use head -2 it's not good because I have already checked the first line. I'd like something like this: while test $i -le $max do grep "$3" `head -$i temp.txt` >... (4 Replies)
Discussion started by: Max89
4 Replies

7. Shell Programming and Scripting

grep on specific line of the file

Hi, how can we search for a word (with case ignore )on specific line numbers ex: Awk /^regEX/ with condition on first line or second line Awk/^ regex1/ on line 1 Awk /^regEX2/ on line 3 thanks in advance (4 Replies)
Discussion started by: rider29
4 Replies

8. UNIX for Dummies Questions & Answers

(cont) Retrieve line from a file based on a value in specific column

HI, Your help was great: awk -F":" '$5 ~ /^P/{print }' file I would like to know what changes need to be done to this line code, so that I can put it in a shell script and call it as the example below. example: countries that start with chacater 'P' > country P Result: ... (0 Replies)
Discussion started by: efernandes
0 Replies

9. UNIX for Dummies Questions & Answers

Retrieve line from a file based on a value in specific column

Hi, I have a file that has several values seperated by ":" 2006:John:Student:Football:Portugal:Cinema 2006:James:Engineer:Basket:Poland:Theatre 2007:Lucy:Diver:Gymnastic:England:Music 2007:Smith:Plumber:Basket:Spain:Poker I need make a filter based on the 5th field to find countries that... (1 Reply)
Discussion started by: efernandes
1 Replies
Login or Register to Ask a Question