Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Friends, I have fdisk -l output in one file called test1.txt.

Now I want to get the device name only using awk.

How to get a device name?

I want output like this:

/dev/sda1
/dev/sda2
/dev/sda3
/dev/sdb1
/dev/sdc1
share|improve this question
4  
The usual questions: What have you tried yet? What were your results? – n.st Mar 2 '14 at 7:13
    
I'd suggest dropping the awk bit from your question. As was stated on the other Q you asked with a similar title it isn't relevant. unix.stackexchange.com/questions/117739/… – slm Mar 2 '14 at 7:49

2 Answers 2

awk '/^\/dev\// { print $1 }' test1.txt

Assuming this correlates to your fdisk output...

share|improve this answer

I don't see any reason to do this using fdisk and awk -- just get the device names from /dev:

printf '%s\n' /dev/[sh]d*

If you only want the partitions and not whole disks, limit the glob to look for a number in the name:

printf '%s\n' /dev/[sh]d*[[:digit:]]*

You can also query /dev/disk, but this may contain some devices you don't care about (the device mapper, for example):

readlink -f /dev/disk/by-id/*
share|improve this answer
    
readlink -f command not work – rajcoumar Mar 2 '14 at 8:01
    
"Not work" in what way? – Chris Down Mar 3 '14 at 4:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.