Search and delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and delete
# 1  
Old 04-30-2012
Search and delete

A file(example viv.txt) contains a n number of rows like
Code:
1,2,3,4,5,6,7,8
11,22,33,44,55,66,77,88
1,3,9,7,8,5,2,6,4

Requirement:
If number "5" exist in the sixth position then it should delete the whole line.like this it should check for all rows in a file(viv.txt)
.

please help on this.

Last edited by joeyg; 04-30-2012 at 12:47 PM.. Reason: Please wrap data and scripts with CodeTags
# 2  
Old 04-30-2012
Code:
awk -F, '$6 == 5 {next}1' viv.txt > output

This User Gave Thanks to neutronscott For This Post:
# 3  
Old 04-30-2012
Or just
Code:
awk -F"," '$6 != 5'

A bare expression like that is an implied "if such-and-such, then print", like
Code:
{ if($6 != 5) { print } }

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 05-02-2012
above command is putting result in a file "output",i want to do changes in source file"viv.txt" itself.

Last edited by katakamvivek; 05-02-2012 at 06:33 AM..
# 5  
Old 05-02-2012
A crude way of doing it...

Code:
sed -n '/[0-9]\{1,\},[0-9]\{1,\},[0-9]\{1,\},[0-9]\{1,\},[0-9]\{1,\},5,/!p' viv.txt|tee viv.txt >/dev/null

# 6  
Old 05-02-2012
I'd recommend still using a temp file, and then moving it on top.

Code:
awk -F"," '$6 != 5' viv.txt > viv.tmp && mv viv.tmp viv.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search and delete a row which is delimited by |^

I have a sample text file like this. CampaignId|^CampaignCd|^InsertionOrderCd|^OwningAdvertiserCd|^CampaignName 998201|^T15-06|^T15|^|^GTA 160x160 998277|^T15-07|^T15|^TEST|^GTA 160x160 998297|^T15-07|^T15|^TEST2|^GTA 160x160 I want to delete the line only when the 4th field is empty. ... (2 Replies)
Discussion started by: Tuxidow
2 Replies

2. UNIX for Beginners Questions & Answers

Search and Delete pattern with Control M

Hi I have data file like below: NET_SALES^M ^M---- new fields for -- ^M ,YABA_FLAG^M ,DOO_FLAG^M My requirement is to search for atleast 2 -- and remove all the words till first ^M is encountered. In above case, output should be like NET_SALES^M ^M ,YABA_FLAG^M ,DOO_FLAG^M TIA... (4 Replies)
Discussion started by: dashing201
4 Replies

3. Linux

How can I search and delete mail?

Hi, I'd like to delete emails on one of my Linux boxes using a criteria and I don't really know where to start. Any suggestions? The emails I'd like to delete have all the following sub-string: checkdefunct.sh.sh I have more than 187.000 emails and 90% of them I'd like to get rid of. ... (1 Reply)
Discussion started by: fabiogilr
1 Replies

4. Shell Programming and Scripting

all files-search and delete

I have n number of files like custpoten_123.txt custpoten_456.txt custpoten_789.txt custpoten_765.txt from above all files i want to serach for a particular number and it should delete the whole line.i have a code for search and delete. code is #!/usr/bin/sh... (6 Replies)
Discussion started by: katakamvivek
6 Replies

5. Shell Programming and Scripting

search and delete the lines in a file

HI group members I am new in unix I want to search # symbol in a file. if found need to delete the entire row in the file. need to move the actual data(with out # symbol data) to another file. Thanks (2 Replies)
Discussion started by: pmreddy
2 Replies

6. UNIX for Dummies Questions & Answers

Linux novice - Search and delete

Hi unix masters, Im needing some guidance or a small code to enlight my problem. Problem Example: I have 3 different text ascii files. At each file, inside the text have repeater marks. --text 1 start-- 123 -> mark anytextanytext anythinganything 123 ->mark blahblah blah ...... (6 Replies)
Discussion started by: atnoz
6 Replies

7. Shell Programming and Scripting

Search and delete

Gurus I have a CSV containing 60K records.Each row has 8 columns. On some rows ,for the 7th column ,i find word 'UnknownState(898914497)' repeated many times. e.g <N_HOST> <tcp> <*> <*> <*> <*> ... (1 Reply)
Discussion started by: ak835
1 Replies

8. Shell Programming and Scripting

search 2 lines and delete above line

Hi, I've been searching in this forum for the last 4 hours trying to do one thing: search 2 lines and delete the above line. So far I have not be able to find something similar in this forum, so I need help. This is what I'm trying to do. For example, I have a file called file1: file1 word1... (4 Replies)
Discussion started by: shamushamu
4 Replies

9. Shell Programming and Scripting

Search text and delete

After searching for a specified string, I would like to delete couple of rows from the file and continue searching. Basically, I would like to search through a text file that holds logs with date-time stamp in them and then clean up the file if the log entry is more than 2 days old. Example log... (0 Replies)
Discussion started by: new2shell
0 Replies

10. Shell Programming and Scripting

search and delete a line

Folks, I have a set of list that contains file names. I want to search through each of the list and delete any file that is found in the list. eg. LIST_A contains: aaa bbb ccc ddd eeee LIST_B contains: aab aac adb aed assuming I want to... (6 Replies)
Discussion started by: odogbolu98
6 Replies
Login or Register to Ask a Question