Remove second last row in file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove second last row in file
# 1  
Old 08-11-2011
Remove second last row in file

My source contain like this
%%START CBLOADER CBLOADER BRBAI2 000090
01,011600033,011600033,110516,0801,3,90,,2/
02,011600033,011103093,1,110317,0801,,2/
%%END BRBAI2 000644
sub
i want remove header and second last row in given file
My output like this
01,011600033,011600033,110516,0801,3,90,,2/
02,011600033,011103093,1,110317,0801,,2/
sub
# 2  
Old 08-11-2011
if you last second row always has the END then you can try this.

Code:
 
$ sed -n ' /END/ !p' test
%%START CBLOADER CBLOADER BRBAI2 000090
01,011600033,011600033,110516,0801,3,90,,2/
02,011600033,011103093,1,110317,0801,,2/
sub

If any of the line has the word END then it will not display

---------- Post updated at 12:48 PM ---------- Previous update was at 12:45 PM ----------

Code:
 
$ nawk ' $0!~/START/ && $0!~/END/ {print $0}' test
01,011600033,011600033,110516,0801,3,90,,2/
02,011600033,011103093,1,110317,0801,,2/
sub

# 3  
Old 08-11-2011
This deletes the second to last line of a file from Eric Pement:

Code:
sed -e '$!{h;d;}' -e x datafile

The code is from his sed one-liner doc:
# 4  
Old 08-11-2011
The following statement:
Code:
sed -e '$!{h;d;}' -e x datafile

Will produce the following output:
Code:
%%END BRBAI2 000644

Which is not what the user wants:
Code:
01,011600033,011600033,110516,0801,3,90,,2/
02,011600033,011103093,1,110317,0801,,2/
sub

# 5  
Old 08-11-2011
A simple in place edit for ed:
Code:
printf %s\\n -d 1d w q | ed -s file

In heredoc form:
Code:
ed -s file <<EOED
-d
1d
w
q
EOED

Regards,
Alister
# 6  
Old 08-12-2011
Through sed..
Code:
sed -n '1d;${x;s/\n\(.*\)\n.*/\1/p;g;p};H' inputfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove row 1 and blanks

I am trying to remove $1 along with the blank values from the file. Thank you :). file R_Index Chr Start End Ref Alt Func.IDP.refGene Gene.IDP.refGene GeneDetail.IDP.refGene Inheritence ExonicFunc.IDP.refGene AAChange.IDP.refGene avsnp147 PopFreqMax ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

3. Shell Programming and Scripting

Read row number from 1 file and print that row of second file

Hi. How can I read row number from one file and print that corresponding record present at that row in another file. eg file1 1 3 5 7 9 file2 11111 22222 33333 44444 55555 66666 77777 88888 99999 (3 Replies)
Discussion started by: Abhiraj Singh
3 Replies

4. Shell Programming and Scripting

How to remove words that contain 3+ of the same character in a row?

Hello, I am looking for a way to remove words from a list that contain 3 or more of the same character. For example lets say the full list is as follows ABCDEF ABBHJK AAAHJD KKPPPP NAUJKS AAAHJD & KKPPPP should be removed from this list as obviously they contain AAA and PPPP... (7 Replies)
Discussion started by: colinireland
7 Replies

5. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

6. Shell Programming and Scripting

Remove first row in a list of files

Hi I want to remove the first row in a list of files and am trying to do via the following. I've tried various quotes to redirect the modifed file to a newly named version of itself but no joy. Can you help? > for i in 'ls A*'; do sed '1d' $i > $i"_complete"; done bash: $i"_complete":... (4 Replies)
Discussion started by: ksexton
4 Replies

7. Shell Programming and Scripting

Get a group of line from different file and put them into one file row by row

hi guys, today i'm stuck in a new problem. the title explain more or less but a particular had been omitted. So i'm going to describe below the situation with an example. I have different html files and each of them have a consecutive lines group inside that i want to extract. example: ... (8 Replies)
Discussion started by: sbobotex
8 Replies

8. Shell Programming and Scripting

how to remove a specifed row from a file with AWK

Hi friends, Plz tell how to remove a row from a file thrugh awk command. Thanks in advance,:) (3 Replies)
Discussion started by: sivaranga001
3 Replies

9. Shell Programming and Scripting

remove row if string is same as previous row

I have data like: Blue Apple 6 Red Apple 7 Yellow Apple 8 Green Banana 2 Purple Banana 8 Orange Pear 11 What I want to do is if $2 in a row is the same as $2 in the previous row remove that row. An identical $2 may exist more than one time. So the out file would look like: Blue... (4 Replies)
Discussion started by: dcfargo
4 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question