Removing last two lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing last two lines
# 8  
Old 12-08-2009
My new awk script is like this. Am bit confused having two next statements. I read the file first time to find the values X T for which T=0. Then I pass the file again and I have another next statement.

Code:
BEGIN {
    ARGV[ARGC++] = ARGV[ARGC-1]
}

FNR == NR {
    ++j
    $2 || val[j] = $1
    next
}

FNR == 1 {
    print ""
    print "% ( PHASES"
    print "P"
    print "%)"
    print ""
    print "%( SOURCES"
    OFS = ""
    for ( k = 1; k < j; ++k ) {
       if ( val[k] != 0 && val[k] !~ />/ ) { print "(",val[k],",0.0)" }
    }
    OFS = " "
    print "%)"
    print ""
}

/>/ { if ( FNR > 1) { print "%)"; print "%>"; print "" }
      P = 1
      next
    }

P {
    print "%< SOURCE", ++i
    print "%( PHASE 1"
    P = 0
}

!/>/ {
    print $0
}

# 9  
Old 12-08-2009
Would have been nice if you'd posted the code as Danmero asked!

Maybe you can change:

Code:

(FNR > 1)

to
Code:

((NR != FNR) && (FNR > 1))

# 10  
Old 12-08-2009
Had posted the awk scripts, here it is again. I think everything is ok.

Code:
BEGIN {
    ARGV[ARGC++] = ARGV[ARGC-1]
}

FNR == NR {
    ++j
    $2 || val[j] = $1
    next
}

FNR == 1 {
    print ""
    print "%( PHASES"
    print "P"
    print "%)"
    print ""
    print "%( SOURCES"
    OFS = ""
    for ( k = 1; k < j; ++k ) {
       if ( val[k] != 0 && val[k] !~ />/ ) { print "(",val[k],",0.0)" }
    }
    OFS = " "
    print "%)"
    print ""
}

/>/ { if ( FNR > 1) { print "%)"; print "%>"; print "" }
      P = 1
      next
    }

P {
    print "%< SOURCE", ++i
    print "%( PHASE 1"
    P = 0
}

!/>/ {
    print $0
}

# 11  
Old 12-08-2009
Actually, forget the change in my last post, you don't need it.

If your script gives the output you want, then it's OK! Does it?
# 12  
Old 12-08-2009
I agree with you, don't need the last post. Was just trying to think through it and understand how you done it. I understand now. Thanks very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

3. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

4. Shell Programming and Scripting

Removing lines from a file

Hi, I have a linux server that was hacked and I have a bunch of files that sporadically contain the following lines through out the file: <?php eval(base64_decode("Xxxxxxxxxxxxxx/xxxxxxxx")); I did't put the exact lines of the file in this post. The "Xxxx" are random letters/numbers.... (8 Replies)
Discussion started by: nck
8 Replies

5. Shell Programming and Scripting

Removing lines with condition

Hello guys, I need help with a script for removing lines that does not satisfy a condition. For example if a file has these lines: aaaa bbbb cccc aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll aaaa bbbb cccc jjjj kkkk lllll dddd eeee ffff dddd eeee ffff Then I want... (4 Replies)
Discussion started by: jaysean
4 Replies

6. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

7. Shell Programming and Scripting

Removing lines having #

I have a script which goes to different directories and gives the values of all the input parameters, Something as follows cd /opt grep script-filter = yes *.conf grep user-and-group-in-same-suffix = yes *.conf grep worker-threads = 300 *.conf grep failover-auth = *.conf grep... (9 Replies)
Discussion started by: openspark
9 Replies

8. Shell Programming and Scripting

Removing lines with sed

Here is some code output that I have: architecture ppc cputype CPU_TYPE_POWERPC cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 4096 size 184464 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 192512 ... (5 Replies)
Discussion started by: pcwiz
5 Replies

9. Shell Programming and Scripting

Removing Blank Lines

Hi i have the below lines from a file 7538 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

10. Shell Programming and Scripting

Removing lines within a file

Hi There, I've written a script that processes a data file on our system. Basically the script reads a post code from a list file, looks in the data file for the first occurrence (using grep) and reads the line number. It then tails the data file, with the line number just read, and outputs to a... (3 Replies)
Discussion started by: tookers
3 Replies
Login or Register to Ask a Question