Loscil94
Loscil94

Reputation: 83

How to extract the first column from an output line?

When executing

sudo fdisk -l | tail -n 1

the result gives me

/dev/sdb1   *        8064     7669823     3830880    b  W95 FAT32

So what I need is to extract just "/dev/sdb1/". Not exactly just sdb1, whatever device that is listed last. What if I have two flash drives and I need the last one?

I've searching everywhere and I couldn't find how. Thanks in advance.

Upvotes: 0

Views: 180

Answers (1)

nu11p01n73R
nu11p01n73R

Reputation: 26677

sudo fdisk -l | tail -n 1 | awk '{print $1}'

will produce as

/dev/sdb1

Upvotes: 1

Related Questions