LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2011, 10:10 AM   #1
JJ Linux
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Rep: Reputation: 0
Question Tail/head


LINUX OS
If i have a text file and i want to get information get info from 4 to 5 different parts of the file...like:
1tttt
2////
3ddd
4rrr
5''''''''
6tttttt
7dddd
8eeee
9yyyyy
10aaaa
11mmmm
12xxxx
13......
14>>>>>

.. i want to get the info from 1 to 3, 5 to 6, 9 to 10 and 11 to 14.. i tried the head and tail...but its not giving me want i want.. i there away to do this using the head/tail command or another command... yea im new to scripting....
 
Old 02-11-2011, 10:17 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Here is one possibility:
Code:
sed -n '1,3p;5,6p;9,10p' file
... and so on.
[edit]
I assume that by 1 to 3 you mean line numbers and not some anchors in your script. Meaning, the preceding numbers are not really in your script, are they?

Last edited by crts; 02-11-2011 at 10:19 AM.
 
Old 02-11-2011, 10:23 AM   #3
JJ Linux
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Tail/head

no the numbers are not in the file.. i just put the numbers there so i can explain my qusetions,, thanks for ur reponse
 
Old 02-11-2011, 10:32 AM   #4
JJ Linux
LQ Newbie
 
Registered: Feb 2011
Posts: 3

Original Poster
Rep: Reputation: 0
THANKS CRTS.. it worked...
 
Old 02-11-2011, 11:06 AM   #5
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 45
Code:
$ ruby -ne 'print if $..to_s =~ /^([1-3]|[5-6]|9|10|1[1-4])$/' file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Samsung Galaxy Tab vs Apple iPad - specifications and features go head-to-head LXer Syndicated Linux News 0 10-06-2010 09:41 PM
tail the output of tail -n 1 raj k yadav Linux - Newbie 5 02-07-2010 12:26 AM
more efficient {min,max} than "sort | {head,tail} -1"? magicbronson Linux - Software 17 07-04-2009 01:26 PM
How to make newer "tail" behave like older "tail" rylan76 Linux - Software 4 12-07-2007 05:27 AM
x86 Solaris 9 XSun and Matrox G550 dual-head... one head down, one to go. finegan Solaris / OpenSolaris 4 03-11-2003 01:39 PM


All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration