Need to remove multiple text from a single file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to remove multiple text from a single file
# 1  
Old 12-27-2009
Lightbulb Need to remove multiple text from a single file

Dear all,

I have a file which have let us say records from A-Z.

Now I want to remove multiple letter from this file using single command.. let us say I want to remove A,F,K,Y,U,P,B,S,D.

I can use grep -v command but for this case i need to rerun the file several time i wana avoid using multiple command and wants the result from single command also output file should also be in a single file.Smilie

Can anyone advice.
# 2  
Old 12-27-2009
To remove A and F you can do something like:

Code:
awk '
!/A/ &&
!/F/ &&
' file > newfile

# 3  
Old 12-27-2009
awk is usually far more elegant for this sort of thing but I think you answered your own question, you can of course use multiple "grep -v" in one go, e.g.:
Code:
$ grep -v A inputfile | grep -v F | grep -v K | grep -v Y | grep -v U | grep -v P | \
  grep -v B | grep -v S | grep -v D > outputfile

If each record starts with the letter concerned then using:
Code:
grep -v "^A"

for each "grep -v" would be better, i.e. remove all lines that start with a capital A.
# 4  
Old 12-27-2009
How about:
Code:
egrep -v "^(A|F|K|Y|U|P|B|S|D)" infile

Code:
sed "/^\(A\|F\|K\|Y\|U\|P\|B\|S\|D\)/d" infile

Code:
sed -r "/^(A|F|K|Y|U|P|B|S|D)/d" infile

or in this case:
Code:
sed '/^[AFKYUPBSD]/d' infile

You can leave the caret (^) out if do not only want to delete records that start with a letter but any record that contains a lettter.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove single @ on line from file

Hi All, So I have to remove all the @hostnames from a file, the problem is, there are instances where @ is used for other things... For example: example text: @This is some text in between some at signs@ @This is some more text@ This is a line that will contain a username and his/her... (5 Replies)
Discussion started by: joeg1484
5 Replies

2. UNIX for Beginners Questions & Answers

Output file name and file contents of multiple files to a single file

I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt. I need each line prefaced with the hostname. I am unsure how to do this. --- Post updated at... (5 Replies)
Discussion started by: Kentlee65
5 Replies

3. Shell Programming and Scripting

Execution of loop :Splitting a single file into multiple .dat file

hdr=$(cut -c1 $path$file|head -1)#extract header”H” trl=$(cut -c|path$file|tail -1)#extract trailer “T” SplitFile=$(cut -c 50-250 $path 1$newfile |sed'$/ *$//' head -1')# to trim white space and extract table name If; then # start loop if it is a header While read I #read file Do... (4 Replies)
Discussion started by: SwagatikaP1
4 Replies

4. Shell Programming and Scripting

Remove multiple lines from a text file

Hi I have a text file named main.txt with 10,000 lines. I have another file with a list of line numbers (around 1000) of the lines to be deleted from main.txt file. I tried with sed but it removes only a range of line numbers. Thanks for any help!! (1 Reply)
Discussion started by: prvnrk
1 Replies

5. UNIX for Dummies Questions & Answers

Pdftotext from multiple pdf files to a single text file

I have a directory having a number of pdf files. I want to convert all the files to text, stored in a single text file The following creates multiple text files ls *.pdf | xargs -n1 pdftotext (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

7. UNIX for Advanced & Expert Users

awk - remove block of text, multiple actions for 'if', inline edit

I'm having a couple of issues. I'm trying to edit a nagios config and remove a host definition if a certain "host_name" is found. My thought is I would find host definition block containing the host_name I'm looking for and output the line numbers for the first and last lines. Using set, I will... (9 Replies)
Discussion started by: mglenney
9 Replies

8. Shell Programming and Scripting

Single to multiple line file

I am working with single line file with 589744523 characters having 542 "^M" (line feed) character. I want to make 542 different lines file from the single line file thr. shell program only (it can be done thr vi command) rd anil sorry for duplicate post previously, actually i don,t know... (6 Replies)
Discussion started by: anil_kut
6 Replies

9. Shell Programming and Scripting

Create multiple text file from a single text file on AIX

Hi I need to create multiple text files from onc text file on AIX. The data of text files is as below: ********************************************** ********************************************** DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:45:42 2009 Copyright (c) 1982,... (11 Replies)
Discussion started by: lodhi1978
11 Replies

10. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies
Login or Register to Ask a Question