Variable storage using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable storage using awk
# 1  
Old 05-31-2012
Variable storage using awk

Hi,

there is a file which contains some values in column format. I want to store those values in a variable.but when i am using awk it is storing all the values at a time.
Code:
x=`awk '{print $1}' test2.txt`
echo $x
ab cd mn jk yt

but i want the values to be stored one by one in that variable.
like
Code:
x=`awk '{print $1}' test2.txt`
echo $x
ab
echo $x
cd

suggestions please.

Last edited by Franklin52; 05-31-2012 at 08:36 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 05-31-2012
Try:
Code:
while read x rest; do
  echo "$x"
done < test2.txt


Last edited by Scrutinizer; 05-31-2012 at 08:57 AM..
# 3  
Old 05-31-2012
actually my input file is in this format

timestamp errormessage errorcode description

from this file i want to pickup the errorcode column and store it in some variable. but when i using awk it is storing all the values inside that column in that variable.i want one value at a time in that variable.

I am using awk as i want to pick a column from a file.
# 4  
Old 05-31-2012
Code:
while read timestamp errormessage errorcode description
do
  echo "Error code: $errorcode"
done < test2.txt

Is error message one word? Otherwise please post a sample of your input file.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Programming

Synchronization Variable Storage

We know that all the threads in process share the process address space. We have various synchronization mechanisms like semaphore, mutex, spinlock, critical sections etc . used for thread syncronization. I want to know in which part of the process address space are these synchronization... (2 Replies)
Discussion started by: rupeshkp728
2 Replies

2. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

3. Programming

Variable storage locations ...

I've got the following two queries: 1) What's the difference in performance if a variable storage is at bss and not at the data section (apart from the initialization to zero in case of data section variables --like static variables). In general, why a developer need to bother about the... (1 Reply)
Discussion started by: Praveen_218
1 Replies

4. Programming

static variable storage

Hi, Where are the static variables actually stored in memory. Is it in .bss? In that case how is its storage different from global variables? From the ELF data is it possible to see the storage of different variables used in the program? eg: static int temp1; int gtemp1; main() {... (1 Reply)
Discussion started by: naan
1 Replies

5. Shell Programming and Scripting

Awk: Is it possible to release storage?

Hello, Is it possible in awk to release storage that has been allocated? I am reading two large similar text files and comparing them to create a delta. Each time I read a line from a file I store it in an array - one for each file. It is impossible to know in advance how far it may be... (2 Replies)
Discussion started by: hedles
2 Replies
Login or Register to Ask a Question