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..

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:

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.. :confused: Someone please help me out.....

# 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
#
# 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:

# 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:

$ 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,

1 Like

Hi,

you can try this

cat filename|tail +7|head -3
grep -v "^$" filename|sed -n '6,8p'

:slight_smile:

1 Like

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