Search and remove in .txt


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Search and remove in .txt
# 1  
Old 04-17-2012
Search and remove in .txt

hi all
I know this is a very simple question but any help would be much appreciated. with other threads not so far having come up with a solution.

I have many long .txt files which have column which looks something like this:
Code:
head test.txt
-3.3
2.3
-11.1
....
1.2
....
-3.1
....

All I want to do is to delete the lines which have the "..." string on them.

I have tried for example this command, but this seems to remove all the positive values in the file for some reason:
Code:
sed 's/^....$//' test.txt > test2.txt

I'm sure there is a very simple way using awk, sed, grep, etc so if anyone can enlighten I'd be very grateful.

cheers,
epf
# 2  
Old 04-17-2012
. is a special character in regular expressions which means 'one of any character', i.e. your regex will match anything that is four characters long. To make it match only literal ., you have to use \. in the regex.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-17-2012
The quickest way for me would be to do this:

Code:
grep -v "\.\.\.\." test.txt > test2.txt

This User Gave Thanks to de_day For This Post:
# 4  
Old 04-17-2012
Code:
grep '[0-9]' file

Code:
grep -vF .... file


Last edited by Scrutinizer; 04-17-2012 at 04:20 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 04-30-2012
thanks a lot everyone, all of the above worked for me!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears i use bash shell i have INPUT.txt like this number of columns different in one some row have 12 , some 11 columns see last column INPUT.txt CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 63 M 27 BS/BA TEHRANI 3 4 298320 310050... (2 Replies)
Discussion started by: alii
2 Replies

2. UNIX for Advanced & Expert Users

How to remove degree symbol from the TXT files?

I have TXT files to process but they contain the degree symbols in them due to which the processing program fails on these files. I want a unix command that will remove the degree symbols from these files. I tried using the sed command: sed 's///g' filename but it did not work. This issue... (14 Replies)
Discussion started by: khedu
14 Replies

3. Shell Programming and Scripting

Pattern search and save it as .txt file with some name..

Hello, I have a note pad at /usr/abc location with the following content, since it is a huge file i need to split it into multiple .txt files. A123|akdhj |21kjsdff |b212b1b21 |0 A123asdasd |assdd |asdasdsdqw|6 A123|QEWQ |NMTGHJK |zxczxczx|3 A123|GEGBGH |RTYBN ... (15 Replies)
Discussion started by: j_panky
15 Replies

4. UNIX for Dummies Questions & Answers

How to remove characters from multiple .txt files

Friends, I want to remove charecters from multiple .txt files. Foe example : In this .txt files there are many "ctrl m" present in last of each line in one .txt file. I want to remove "ctrl m" from each line from all .txt files. Need your help regarding this. (4 Replies)
Discussion started by: meetsubhas
4 Replies

5. UNIX for Dummies Questions & Answers

to remove space in a txt file

I want to fetch text after the first occurance of the word "started at" i.e. consider a text written below... echo 'hi how r u ' Started at MON Jan 11 00:03:24 EST 2009 echo 'hi how is ur job goin on' Started at Sun Jan 11 00:03:24 EST 2004 Started at TUE Jan 11 00:03:24 EST 2005 Started... (19 Replies)
Discussion started by: manit
19 Replies

6. Shell Programming and Scripting

How to remove certain lines in multiple txt files?

Hi , I have this type of files:- BGH.28OCT2008.00000001.433155.001 BGH.28OCT2008.00000002.1552361.001 BGH.28OCT2008.00000003.1438355.001 BGH.28OCT2008.00000004.1562602.001 Inside them contains the below: 5Discounts 6P150 - Max Total Usage RM150|-221.00 P150 EPP - Talktime RM150... (5 Replies)
Discussion started by: olloong
5 Replies

7. Shell Programming and Scripting

sed to remove last 2 characters of txt file

sed 's/^..//' file1.txt > file2.txt this will remove the first two characters of each line of a text file, what sed command will remove the last two characters? This is a similar post to my other....sry if I'm being lazy.... I need a file like this (same as last post) >cat file1.txt 10081551... (1 Reply)
Discussion started by: ajp7701
1 Replies

8. UNIX for Dummies Questions & Answers

Compare and Remove duplicate lines from txt

Hello, I am a total linux newbie and I can't seem to find a solution to this little problem. I have two text files with a huge list of URLS. Let's call them file1.txt and file2.txt What I want to do is grab an URL from file2.txt, search file1.txt for the URL and if found, delete it from... (11 Replies)
Discussion started by: rmarcano
11 Replies

9. Shell Programming and Scripting

remove first column of a space delimited txt

how to remove the first column of a space delimited txt file? there are 12+ columns... what is the cleanest way? could use awk and print all but the first, but it looks kinda ugly awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10" "$11" "$12"}' file.txt whats a better way? (1 Reply)
Discussion started by: ajp7701
1 Replies

10. UNIX for Dummies Questions & Answers

rm: cannot remove `test1.txt': Permission denied

This issue is on RedHat 4AS, and I am pretty sure this is a very basic permission issue. I need to give permission for everyone to move/delete the file that is created by me. How do i do that? Here are the commands I issued: $ id uid=680(praveen) gid=1003(nextgen) groups=1003(nextgen)... (2 Replies)
Discussion started by: praveen_indramo
2 Replies
Login or Register to Ask a Question