Remove 1st two rows and last 2 rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove 1st two rows and last 2 rows
# 1  
Old 08-30-2010
Remove 1st two rows and last 2 rows

Hi All,
I need to remove 1st 2 line from head and last 2 line from last.
I thought it would be possible by using the Head and tail command.
But after i am using it is not possible by it.
Example:Input file
Code:
1
2
3
4
5

Example: Output file
Code:
3

But my head and tail command are not working?
Code:
head -n 2 filename|tail -n 2

# 2  
Old 08-30-2010
Hi

(not tested)

Code:
#x=`cat file | wc -l`
#awk 'NR>2 && NR+1<'$x'' file

Guru.
# 3  
Old 08-30-2010
If your head and tail support it (Linux version should work):
Code:
tail -n+3 file | head -n-2

# 4  
Old 08-30-2010
Code:
cnt=`cat filec | wc -l`
tail -`expr $cnt - 2` filec | head -`expr $cnt - 4`

# 5  
Old 08-30-2010
Hi guys thanks for help.
But i want to do this in one line only.
As i can execute only one command.
Code:
tail -n+3 file | head -n-2

Is not working.
# 6  
Old 08-30-2010
Code:
# head -n 3 file | tail -n1
3

# 7  
Old 08-30-2010
Hi Sorry for wrong input
Input file
Code:
1
2
3
:
:
50

Output file
Code:
3
:
:
48

Any time i should always remove 1st two row from top and bottom.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove rows containing commas with awk

Hello everyone, I have a dataset that looks something like: 1 3 2 2 3 4,5 4 3:9 5 5,9 6 5:6 I need to remove the rows that contain a comma in the second column and I'm not sure how to go about this. Here is an attempt. awk 'BEGIN {FS=" "} { if ($2!==,) print }'Any help is appreciated. (5 Replies)
Discussion started by: Rabu
5 Replies

2. Shell Programming and Scripting

Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file. Any help would be great Thanks (6 Replies)
Discussion started by: kylle345
6 Replies

3. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

4. Shell Programming and Scripting

Remove rows with e column values

Hi All, I have a big file with 232 columns and 9 million rows, I want to delete all rows with same column values in col3 through col232. Also the output should be sorted based on first 2 columns. Here is a reduced example with 6 columns. I want to remove rows with duplicate values in col3... (9 Replies)
Discussion started by: alpesh
9 Replies

5. Shell Programming and Scripting

Find and Remove rows

******************************************* * ROW * ******************************************* CODE:CODE1 FILE: FILE1 FIELD: FIELD1 KEY: KEY1 ORA-00001: unique constraint (ETL.KEY_PK) violated ******************************************* * ROW * *******************************************... (7 Replies)
Discussion started by: Shanks
7 Replies

6. Shell Programming and Scripting

remove consecutive duplicate rows

I have some data that looks like, 1 3300665.mol 3300665 5177008 102.093 2 3300665.mol 3300665 5177008 102.093 3 3294015.mol 3294015 5131552 102.114 4 3294015.mol 3294015 5131552 102.114 5 3293734.mol 3293734 5129625 104.152 6 3293734.mol ... (13 Replies)
Discussion started by: LMHmedchem
13 Replies

7. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

8. Shell Programming and Scripting

Remove Blank Rows

Hello All, I am having a problem in automating my UNIX Script to remove the blank spaces in between records. When I incorporate it into my script, the output file is deleting the whole content :confused: Basically this is what I am trying to do: File contains data like this:... (14 Replies)
Discussion started by: Vinsanity
14 Replies

9. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

10. UNIX for Dummies Questions & Answers

Remove rows from file

Hi to all,this is my first post here. I've a file as name 89 78 09 67 othername how I can remove the word name and othername from this file, and an eventually blank row in it?Thanks in advance. (2 Replies)
Discussion started by: cv313x
2 Replies
Login or Register to Ask a Question