Cut lines from and to in a textfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut lines from and to in a textfile
# 1  
Old 06-12-2014
Cut lines from and to in a textfile

i am having a text file like below


Code:
rama
surya
pandu
latha
singh
raja

i want to get the new file from 3 to 5

i.e
Code:
pandu
latha
singh


please help

Last edited by Don Cragun; 06-12-2014 at 06:37 AM.. Reason: Add CODE tags.
# 2  
Old 06-12-2014
Code:
$ awk 'FNR>=3 && FNR<=5' infile > outfile

Code:
$ sed -n '3,5p' infile > outfile

Code:
$ head -n 5 infile | tail -n 3 >outfile

---------- Post updated at 02:11 PM ---------- Previous update was at 02:03 PM ----------

Code:
$ perl -ne 'print if 3..5' infile >outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replicating certain lines in a textfile

I am very new to to shell scripting and facing a problem that I can't seem to solve. I want to write a bash script that edits file1.txt and saves it as file2.txt. This is what the files should look like: file1: textline1 textline2 startCopy copyThis endCopy textline3 textline4 file2: ... (6 Replies)
Discussion started by: sandy90
6 Replies

2. Shell Programming and Scripting

How to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

3. UNIX for Dummies Questions & Answers

Cut particular lines

All, I would like to cut all the lines from the log file for the timestamp . I'm not clear about how to apply grep ,awk here.Can you help me on this ? My logfile: ********** Wed Feb 20 03:48:26 2013 Thread 1 advanced to log sequence 400 (LGWR switch) Thu Feb 21 02:34:23 2013... (1 Reply)
Discussion started by: arul1185
1 Replies

4. Shell Programming and Scripting

Find a string in textfile, erase $num lines after that string

I have a textfile containing text similar to the following pattern: STRING1 UNIQUE_STRING1 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING2 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING3 STRING2 STRING3 (6 Replies)
Discussion started by: ilcsfe
6 Replies

5. UNIX for Dummies Questions & Answers

cut particular lines from a file

how can I cut out partiluar lines like from line 233 to 347 ? any idea? (2 Replies)
Discussion started by: kvok
2 Replies

6. Shell Programming and Scripting

How to delete all lines with less then 32 characters from a textfile?

I need to delete all lines with less then 32 characters from a textfile. :) (15 Replies)
Discussion started by: anna428
15 Replies

7. Shell Programming and Scripting

cut lines in a file.

Hi Everyone, I have a file a.txt, inside is Mon Jul 20 00:05:07 2009 12 Mon Jul 20 00:05:08 2009 1 The output should be a.txt, inside is 00:05:07 12 00:05:08 1 My method is `cat a.txt | cut -f4,6 -d' ' > a.txt.tmp;mv -rf a.txt.tmp a.txt`; Is any good way to do this? like perl... (5 Replies)
Discussion started by: jimmy_y
5 Replies

8. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

9. Shell Programming and Scripting

Cut lines before keyword

Hi, How to cut all lines in file before keyword? from 1 2333214 word ...... some text 2 234343 234234 word ...... some text 3 234324 324 3234 word ...... some text to 1 2333214 2 234343 234234 3 234324 324 3234 (4 Replies)
Discussion started by: Trump
4 Replies

10. Shell Programming and Scripting

Parsing textfile problem with cut

Hi, I have a textfile with several lines like this: text num: USER text (num) num num I need all these stuff. Problem is, how to get these stuff after ":". USER is a username and all chars are possible, even whitespace. So I cant use cut. Any ideas? (3 Replies)
Discussion started by: mcW
3 Replies
Login or Register to Ask a Question