Extracting lines after nth LINE from an output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting lines after nth LINE from an output
# 1  
Old 04-21-2012
Question Extracting lines after nth LINE from an output

Hi all,

Here is my problem for which i am breaking my head for past three days..

I have parted command output as follows..
Code:

Model: ATA WDC WD5000AAKS-0 (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  65.5GB  65.5GB  primary  ext3         boot 
 2      65.5GB  67.7GB  2147MB  primary  linux-swap        
 3      67.7GB  500GB   432GB   primary  ext3              

Information: Don't forget to update /etc/fstab, if necessary.   

I need the lines exactly the partition informations as:

Code:
1      32.3kB  65.5GB  65.5GB  primary  ext3         boot 
2      65.5GB  67.7GB  2147MB  primary  linux-swap        
3      67.7GB  500GB   432GB   primary  ext3           

How can i get that one.. Smilie Someone please help me out.....

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-21-2012 at 07:48 AM..
# 2  
Old 04-21-2012
Code:
# awk ' $1 ~ /^[0-9]/' file
 1      32.3kB  65.5GB  65.5GB  primary  ext3         boot
 2      65.5GB  67.7GB  2147MB  primary  linux-swap
 3      67.7GB  500GB   432GB   primary  ext3
#

Code:
# cat file
Model: ATA WDC WD5000AAKS-0 (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  65.5GB  65.5GB  primary  ext3         boot
 2      65.5GB  67.7GB  2147MB  primary  linux-swap
 3      67.7GB  500GB   432GB   primary  ext3

Information: Don't forget to update /etc/fstab, if necessary.
#

if output came from another command just pipe it to awk

Edit: or use grep:
Code:
# grep '^.[0-9]' file
 1      32.3kB  65.5GB  65.5GB  primary  ext3         boot
 2      65.5GB  67.7GB  2147MB  primary  linux-swap
 3      67.7GB  500GB   432GB   primary  ext3
#

I forgot about sed:

Code:
$ sed -n '/^.[0-9]/p' file
 1      32.3kB  65.5GB  65.5GB  primary  ext3         boot
 2      65.5GB  67.7GB  2147MB  primary  linux-swap
 3      67.7GB  500GB   432GB   primary  ext3
$

Kind regards,

Last edited by haczyk; 04-21-2012 at 08:32 AM.. Reason: Add grep && sed code
This User Gave Thanks to haczyk For This Post:
# 3  
Old 04-21-2012
Hi,

you can try this

Code:
cat filename|tail +7|head -3


Code:
grep -v "^$" filename|sed -n '6,8p'

Smilie
This User Gave Thanks to sdebasis For This Post:
# 4  
Old 04-21-2012
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Redirecting output from Nth line

Dear All, I have a shell script which output like some thing below 1.2.3.4 1.2.3.5 1.2.3.6 ------ Start of CSV ------- id ,number ,name ,location 1,101,asp,xyz 2,102,dsp,ert Now i need to redirect this output to csv file but from particular line number. i mean, first i need to skip... (5 Replies)
Discussion started by: onenessboy
5 Replies

3. UNIX for Dummies Questions & Answers

Extracting the two lines where the first line is matched

Hi, If I have a file of something like @hg19_gold_AL122127.6-131160 GCTTCATCATGCATGGATAGGCTGGCGCCTTTCCTGAGGCCATATGCCGATGGATATG @hg19_gold_AL122127.6-131159 CTTTAATATTTCCGCCACCATCCTGAGTGAATCCCAGCAAGGACAGTCTTTGGGGATT @hg19_gold_AL122127.6-131158... (4 Replies)
Discussion started by: jyu429
4 Replies

4. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

5. Shell Programming and Scripting

How to output all lines following Nth occurrence of string

Greetings experts. Searched the forums (perhaps not hard enough?) - Am searching for a method to capture all output from a log file following the nth occurrence of a known string. Background: Using bash, I want to monitor my Oracle DB alert log file. The script will count the total # of... (2 Replies)
Discussion started by: cjtravis
2 Replies

6. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

7. Shell Programming and Scripting

Extracting line matching a phrase and then the next lines after it

Hi all, I was wondering if someone could tell me a way to extract from a file lines where you search for a phrase and then also extract the next X lines after it (i.e. take a block of text from the file)? Example { id=123 time=10:00:00 date=12/12/09 { ........ ... (6 Replies)
Discussion started by: muay_tb
6 Replies

8. Shell Programming and Scripting

Logfile - extracting certain lines to concatenate into 1 line

I've got a log file from automatic diagnostic runs. The log file is appended to each time an automatic log is run. I'd like to just pull certain lines from each run in the log file, and concatenate them into 1 comma delimited line (for export into excel or an html table). Each diagnostic run... (3 Replies)
Discussion started by: BecTech
3 Replies

9. Shell Programming and Scripting

using tr to put multiple lines of output into one line

Hi all, For a intro UNIX course I'm taking, I need to use the command "tr" to display a file on standard output without any newlines (all on one line). I assume I would start with "cat filename | tr" but don't know what to put after tr. Any ideas would be lovely! Thanks. (3 Replies)
Discussion started by: otes4
3 Replies

10. Shell Programming and Scripting

Need output in different lines not in one single line

I am getting the coutput like this as show below in one single line, where as the command is executed is several lines and the output should also be requied in several lines, not in one single line. Anyone any idea? p4 opened -a | grep *locked* | awk '{ printf $8 }' >/tmp/aa $ cat... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question