LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 06-10-2008, 02:33 PM   #1
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Rep: Reputation: 15
how to get the desired output from the following code:


#!/bin/bash

r=$(grep '^Layout' vdat.txt | awk '{print $3}')
echo $r


the above gives out put
RAID-5 RAID-5 RAID-5 RAID-5

how do i get from the output the first word RAID-5 into a variable for comparison

please help me as soon as poosible.. am a newbie

thanks
 
Old 06-10-2008, 02:51 PM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,397
Blog Entries: 1

Rep: Reputation: 64
You already solved the problem, not in the best way possible, but you did.
Just use the same construction again !

Code:
s=$(echo $r | awk '{print $1}')
ok, you want to know an another way ?
you can use an array of variables and print an element using the array index (starting with zero)...

Code:
r=($(grep '^Layout' vdat.txt | awk '{print $3}'))
echo ${r[0]}
cheers,
 
  


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
rsync error: errors selecting input/output files, dirs (code 3) at main.c(323) cucolin@ Linux - Networking 3 11-20-2007 05:56 PM
how to set the right charset (or desired) amimusa Debian 1 04-05-2007 04:07 AM
output is the code itself aditya1 Programming 13 03-28-2006 02:29 PM
Desired delay in potfix hotrodowner Linux - Software 2 03-11-2005 06:37 AM
gedit output code linmix Linux - Software 1 01-03-2005 08:07 PM


All times are GMT -5. The time now is 08:21 AM.

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