Delete selected lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete selected lines
# 1  
Old 02-22-2014
Delete selected lines

hi Gurus,

I have a source file with more than 10 columns ( not fixed )
I want to delete all the lines on the following condition

1) where i have first column as "UPDATE PLAN ADD RATE SCHEDULE" and fourth column as null

Code:
awk '($1=="UPDATE PLAN ADD RATE SCHEDULE" && $4=="") {print $0}' FS="," Source_File.csv

2) where i have first column as CREATE L2 SUPP PLAN and fifth column as null
Code:
awk '($1=="CREATE L2 SUPP PLAN" && $5=="") {print $0}' FS="," Source_File.csv.

Its a comma seperated files

Last edited by Don Cragun; 02-22-2014 at 04:52 AM.. Reason: Add CODE tags.
# 2  
Old 02-22-2014
Quote:
Originally Posted by r_t_1601
hi Gurus,

I have a source file with more than 10 columns ( not fixed )
I want to delete all the lines on the following condition

1) where i have first column as "UPDATE PLAN ADD RATE SCHEDULE" and fourth column as null

Code:
awk '($1=="UPDATE PLAN ADD RATE SCHEDULE" && $4=="") {print $0}' FS="," Source_File.csv

2) where i have first column as CREATE L2 SUPP PLAN and fifth column as null
Code:
awk '($1=="CREATE L2 SUPP PLAN" && $5=="") {print $0}' FS="," Source_File.csv.

Its a comma seperated files
You say you want to delete lines based on one condition, but you show us two awk scripts that delete all lines except those based on two sets of two conditions.

Are you trying to delete lines that either of these awk scripts print, delete lines that both of these awk scripts print, delete all line except those that either of these awk scripts print, or delete all lines except those that both of these awk scripts print?

Please show us some sample input (in CODE tags) and the corresponding output that you want to produce based on that sample.
# 3  
Old 02-22-2014
Sorry for confusion.

I want to delete all the lines that are selected by the two awk statements i have written. for example Source file
Code:
CREATE L2 SUPP PLAN,2,3,4,5,6,7
CREATE L2 SUPP PLAN,2,3,4,,6,7
CREATE L2 SUPP PLAN,2,5,6,,8,9
UPDATE PLAN ADD RATE SCHEDULE,a,b,,d,e,f
UPDATE PLAN ADD RATE SCHEDULE,1,2,3,4,5,6,7,8
UPDATE PLAN ADD RATE SCHEDULE,1,2,3,4,5,8,9,9

i want to delete

Code:
CREATE L2 SUPP PLAN,2,3,4,,6,7
CREATE L2 SUPP PLAN,2,5,6,,8,9
UPDATE PLAN ADD RATE SCHEDULE,a,b,,d,e,f


Last edited by Don Cragun; 02-22-2014 at 06:41 AM.. Reason: Replace HTML tags with CODE tags.
# 4  
Old 02-22-2014
Try:
Code:
awk -F, '!($1=="UPDATE PLAN ADD RATE SCHEDULE" && $4=="") && !($1=="CREATE L2 SUPP PLAN" && $5=="")' Source_File.csv

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 02-25-2014
Delete Selected lines

Thanks Don this works.

Actually i have control Characters in 4th and 5th Column. hence it's not working on those . how can i delete if the column is either null or has control characters
# 6  
Old 02-25-2014
You need to learn to give a clear description of your input file formats.

Are you now saying that fields 4 and 5 can contain any characters in character class cntrl (including null bytes and newline characters)? Is a\tb\nc\0d (where\t is a tab character, \n is a newline character, and \0 is a null byte) now a valid value in fields 4 and 5?

What does "has control characters" mean? (Contains at least one control character? Contains no characters that are not control characters? Does not contain any character that is not a control character?)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting selected lines in a file

Hi Guys , I have two files say a1 and a2 having following contents a1 dag wfd a2 dag wfd chire hcm I want to delete only the lines in a2 which are in a1 and final output of a2 should be a2 chire hcm (6 Replies)
Discussion started by: Pradeep_1990
6 Replies

2. Shell Programming and Scripting

Selected matching lines

two files: one with the line number only, and the 2nd one with line number and content, as following: line_file.txt 1 3 5 9 23 30 content_file.txt 1|we are the world|good|great 2|easily do this by highlighting you|easily do this by highlighting you|easily do this by highlighting... (2 Replies)
Discussion started by: dtdt
2 Replies

3. Shell Programming and Scripting

sed to delete selected line from file

Ultimate goal is to delete lines from before and after a block of lines in a given file. First attempt was something like this: sed -e '1,/STARTUP/ d' inputfile.txt > outputfile.txt but that deleted everything down to and including the line with STARTUP. I need to delete everything before... (6 Replies)
Discussion started by: edstevens
6 Replies

4. Shell Programming and Scripting

finding least out of selected lines

Hello, I have a file, which looks like: I want to print the row containg "PRO" in second column after comparing and finding the minimum value of fifth column present in all "PRO". and likewise for every other string present in second column. I am using : filename=list... (2 Replies)
Discussion started by: CAch
2 Replies

5. Shell Programming and Scripting

Delete the lines if it matchs a selected string

HI, I need one help to generate the file based on few condition, I need to print only those line which has N and delete the line which as all Y's. ANd I need to compare only the fields which are marked as Y and N . And one more thing is in the below file 1 and file 2 and file2 abc, dbc can... (6 Replies)
Discussion started by: rashmisb
6 Replies

6. Shell Programming and Scripting

Delete a line between selected lines using sed or any other command

I want to delete a line between selected lines using sed: e.g. : Between "bus" to "pins", delete lines conaining "signal" word. Input : bus direction signal new signal old pins signal ok end Desired Output: bus direction pins signal end (4 Replies)
Discussion started by: nehashine
4 Replies

7. Shell Programming and Scripting

How to delete selected string from a file?

awk '!(/^$/||/--/||/selected/||/^ *$/){print "A." $1 " <> B." $1 " or"}' infile my AWK out put is : A.KZ <> B.KZ or A.KZT <> B.KZT or A.KZ_Z <> B.KZ_Z or A.LH <> B.LH or A.MAN<> B.MAN or A.OBJEKT <> B.OBJECT or A.PAK <> B.PAK ; is there any way to controle AWK to not print the... (1 Reply)
Discussion started by: kanakaraju
1 Replies

8. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

9. Shell Programming and Scripting

Process selected lines

I have an if statement where I state that if there are more than one records (lines) found containing a string in a file, then it enters into a while loop to use each line for as many lines as there are and then stop. Trouble is, I can't figure out how to move to the next instance of each line. ... (2 Replies)
Discussion started by: derekphl
2 Replies

10. Shell Programming and Scripting

print selected lines

Hi everybody: I try to print in new file selected lines from another file wich depends on the first column. I have done a script like this: lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" ) ${lines} for lines in ${lines} do awk -v ... (6 Replies)
Discussion started by: tonet
6 Replies
Login or Register to Ask a Question