Find the answer to your Linux question:
Results 1 to 7 of 7
Hi, I want to delete lines which contain the word "Fehler" but for some reason my programm isn't working: Code: BEGIN { FS="|" OFS="|" SUBSEP="|" anzArg = 2 if (ARGC ...
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    2

    gawk - delete line in file

    Hi,

    I want to delete lines which contain the word "Fehler" but for some reason my programm isn't working:

    Code:
    BEGIN { FS="|"
    		OFS="|"
    		SUBSEP="|"
    		anzArg = 2
    		if (ARGC < anzArg) {
    			print "Zuwenig Argumente"
    			print "gawk -f makeEGNinput.awk inputfiles"
    			nosource = "true"
    			exit 1
    		}
    	}
    
    { # Main
    	if (FNR == 1) {
    		outfile = (FILENAME ".load")
    		print ("Outfile: " outfile)
    	}
    	# Delete path
    	split($5,arrDatei,"/")
    	# Delete line with  <Fehler> 
    	if ($5 != "<Fehler>"){
    		n = asort(arrDatei,arrCount)
    		$5 = arrDatei[n]
    	}
    	#print $0
    	print $0 > outfile
    }
    My input file looks like this:
    00036425|06|2010|0001|/usr/swas/pmscp/betr/eis/teis/EGN_00036425_20101013091045.pdf
    00041332|06|2010|0000|<FEHLER>
    00036425|06|2010|0001|/usr/swas/pmscp/betr/eis/teis/EGN_00036425_20101013091045.pdf

    I can somebody help me?

    Thanx
    frog_123

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,098
    Does it need to be gawk?

    grep -v FEHLER inputfile
    should fullfill your requirements.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    2
    thanks a lot for that simple solution!!

  4. #4
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    In any case, you were testing for "Fehler" while expecting "FEHLER".

  5. #5
    Just Joined!
    Join Date
    Jan 2008
    Posts
    5
    Or how about sed?
    sed /FEHLER/d inputfile > outputfile
    or if you want to change the inputfile directly:
    sed -i /FEHLER/d inputfile

  6. #6
    Just Joined!
    Join Date
    Jan 2008
    Posts
    5
    And to correct myself, I see your inputfile contains slashes. Just use any delimiter not in your inputfile, for example:
    sed #FEHLER#d inputfile > outputfile

    Knut

  7. #7
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    And to correct your correction, sed doesn't really care about slashes in its input stream, it's already parsed them out of the pattern. It does, of course, care about slashes in the pattern argument.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...