Remove lines contain certain string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove lines contain certain string
# 1  
Old 05-01-2013
Remove lines contain certain string

i have file input

Code:
aa,20120626 bb,45C

expect to remove all lines when $2 doesn't end with 'C"

output

Code:
bb,45C

i tried this
sed -i -nl -e '/\<C\>/ {p;} ' file1
but the result : sed illegal option -i
# 2  
Old 05-02-2013
Hold on!! You said that you want to delete all the lines that are not ending with "C"

In Sample input there is only one line. aa,20120626 bb,45C according to your requirement, no changes should be made to that line, Correct??

Please put few more sample data.
# 3  
Old 05-02-2013
sorry i mean

file input
Code:
aa,20120626
bb,45C

output should be
Code:
bb,45C

# 4  
Old 05-02-2013
Code:
$ grep "C$" input
bb,45C

# 5  
Old 05-02-2013
Quote:
Originally Posted by radius
expect to remove all lines when $2 doesn't end with 'C"
Code:
awk -F, '$2~/C$/' file

# 6  
Old 05-02-2013
Code:
sed -n "/C$/p" file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate consecutive lines with specific string

Hello, I'm trying to remove the duplicate consecutive lines with specific string "WARNING". File.txt abc; WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 bcd; abc; 123 123 123 WARNING 1234 WARNING 2345 WARNING 2345 efgh; (6 Replies)
Discussion started by: Mannu2525
6 Replies

2. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Linux

How to remove lines without a particular string in either column?

I have a file that looks like this: DIP-27772N DIP-18408N refseq:NP_523941 DIP-23436N|refseq:NP_536784 DIP-23130N|refseq:NP_652017 DIP-22958N|refseq:NP_651195 DIP-20072N|refseq:NP_724597 DIP-22928N|refseq:NP_569972 DIP-22042N|refseq:NP_536744|uniprotkb:P54622... (4 Replies)
Discussion started by: Syeda Sumayya
4 Replies

4. Shell Programming and Scripting

Remove not only the duplicate string but also the keyword of the string in Perl

Hi Perl users, I have another problem with text processing in Perl. I have a file below: Linux Unix Linux Windows SUN MACOS SUN SUN HP-AUX I want the result below: Unix Windows SUN MACOS HP-AUX so the duplicate string will be removed and also the keyword of the string on... (2 Replies)
Discussion started by: askari
2 Replies

5. Shell Programming and Scripting

Remove multiple lines from a particular string to particular string

Hi, I have a file containing the DDLs of tables in a schema. From that I need to remove all the lines from a starting string till a specific string. Here is an example. File1.txt ------------- CREATE TABLE "SCHEMA1"."LKP11_TBL_USERS" ( "ID" NUMBER(8,0) NOT NULL ENABLE, "USER_ID"... (3 Replies)
Discussion started by: satyaatcgi
3 Replies

6. UNIX for Dummies Questions & Answers

Remove lines in a positional file based on string value

Gurus, I am relatively new to Unix scripting and am struck with a problem in my script. I have positional input file which has a FLAG indicator in at position 11 in every record of the file. If the Flag has value =Y, then the record from the input needs to be written to a new file.However if... (3 Replies)
Discussion started by: gsam
3 Replies

7. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

8. Shell Programming and Scripting

Remove lines that match string at end of column

I have this: 301205 0000030000041.49000000.00 2011111815505 908 301205 0000020000029.10000000.00 2011111815505 962 301205 0000010000027.56000000.00 2011111815505 3083 312291 ... (2 Replies)
Discussion started by: herot
2 Replies

9. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

10. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies
Login or Register to Ask a Question