From: Alex Schuster <wonko@wonkology.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Bash script inquiry
Date: Tue, 11 Aug 2009 10:59:21 +0200 [thread overview]
Message-ID: <200908111059.22123.wonko@wonkology.org> (raw)
In-Reply-To: <467A7B499C3F444FA7BA42CB5C5260BA@RichardPC>
Richard Marza writes:
> FILE=`cat filename.txt`
> TICK=`cat filename.txt | wc -l'
> TOCK="0"
>
> while [ $TICK != $TOCK ] ; do
> let $TOCK=$TOCK+1
Or, simpler, as we are using bash: (( TOCK++ ))
> Var1= `cat FirstWordOfFirstColumnOfFirstLine` (This I
> actually achieved with sed and awk)
> Var2=`cat FirstFloatOfFirstLine` (The problem lies here;
> it's my inability to come up with a way of implementing a variable that
> changes along with the counter. so that the second time this is run it
> doesn't do the first line but moved to the second line and the third line
> and so on...)
>
> done
>
> exit 0
What should Var1 contain - "Dbase1" or the content of the file "Dbase1"?
What should Var2 contain - "5.0" or the content of the file "5.0"?
Because you are using cat in the assignment.
If you just need the values in a variable, do it like this:
file=filename.txt
Var1=( $( cat "$file" | awk '{ print $1 }' ) ) # creates an array variable
Var2=( $( cat "$file" | awk '{ print $2 }' ) )
The $() notation does the same as backticks, but is more readable. Using
foo=( ... ) will create foo as an array. I assume there is no whitespace in
your data, that is Var1 will never contain something like "Dbase 1".
${#Var1[@]} will contain the number of elements (your $TICK). To access the
5th element (for example), use ${Var1[4]}.
Oh, an please don't hijack threads by replying to an existing one, but start
a new one. This one appears inside the "Cloning movie DVDs" thread.
And feel free to ask more questions, maybe I got it all wrong.
Wonko
next prev parent reply other threads:[~2009-08-11 8:59 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-11 4:43 [gentoo-user] Cloning movie DVDs with dd - only works after accessing disk with another command? Stroller
2009-08-11 4:47 ` Stroller
2009-08-11 6:51 ` [gentoo-user] " Remy Blank
2009-08-11 7:33 ` [gentoo-user] " Neil Bothwick
2009-08-11 7:47 ` Stroller
2009-08-11 10:24 ` Neil Bothwick
2009-08-11 18:58 ` Stroller
2009-08-12 11:05 ` Neil Bothwick
2009-08-12 20:05 ` [gentoo-user] HandBrakeCLI & undvd. was: Cloning movie DVDs with dd Stroller
2009-08-12 20:43 ` Neil Bothwick
2009-08-14 7:01 ` Stroller
2009-08-11 8:07 ` [gentoo-user] Bash script inquiry Richard Marza
2009-08-11 8:24 ` Etaoin Shrdlu
2009-08-11 8:59 ` Alex Schuster [this message]
2009-08-11 9:27 ` Richard Marza
2009-08-11 9:55 ` Etaoin Shrdlu
2009-08-11 10:17 ` Richard Marza
2009-08-11 10:28 ` Etaoin Shrdlu
2009-08-11 9:38 ` Peter Humphrey
2009-08-11 7:50 ` [gentoo-user] Cloning movie DVDs with dd - only works after accessing disk with another command? Joerg Schilling
2009-08-11 19:16 ` Stroller
2009-08-11 19:31 ` Paul Hartman
2009-08-11 19:36 ` Stroller
2009-08-11 20:02 ` Paul Hartman
2009-08-11 20:41 ` [gentoo-user] HandbrakeCLI vs dvd::rip was: Cloning movie DVDs with dd Stroller
2009-08-11 19:31 ` [gentoo-user] Re: Cloning movie DVDs with dd - only works after accessing disk with another command? Grant Edwards
2009-08-11 20:22 ` Stroller
2009-08-11 22:49 ` Paul Hartman
2009-08-12 0:55 ` Stroller
2009-08-12 10:06 ` Richard Marza
2009-08-11 15:28 ` James
2009-08-11 19:29 ` Stroller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200908111059.22123.wonko@wonkology.org \
--to=wonko@wonkology.org \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox