How to read the value from a specific line and column BASH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read the value from a specific line and column BASH
# 1  
Old 01-12-2010
How to read the value from a specific line and column BASH

Hi All,
I have the same problem as the one posted in
https://www.unix.com/shell-programmin...-variable.html

but I'm using bash.
Can anyone tell me how I have to modify the code to make it bash compatible?

Code:
eval `awk 'NR==3{print "set x="$2}' text1.txt

Thank you,
Sarah
# 2  
Old 01-12-2010
Hi.

Just remove the word set.
# 3  
Old 01-12-2010
or

Code:
x=$(nawk 'NR==3{print $2}' infile)

SmilieSmilie
# 4  
Old 01-12-2010
Thank you,
I have a problem feeding awk the line number as variable:
e.g.
Code:
awk '(NR==$ST_LINE){print $2}' file

won't work
while
Code:
awk '(NR==10142){print $2}' file

does

I tried also {} but it gives an error
# 5  
Old 01-12-2010
Code:
awk 'NR==st{print $2}' st="${ST_LINE}" file

# 6  
Old 01-12-2010
Code:

awk '(NR=='$ST_LINE'){print $2}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

2. Shell Programming and Scripting

Bash script read specific value from files of an entire folder

Hello, I heva a problem creating a script that read specifc value from all the files of an entire folder I have a number of email files into a directory and i need to extrect from each file 2 specific values. After that i have to put them into a new file that looks like that: To: value1 ... (1 Reply)
Discussion started by: ahmenty
1 Replies

3. Shell Programming and Scripting

How to read particular line in file from specific column?

Hi...friends.... I want to create inventory...information for that I need to read some specific row say 2nd row from 1st 3 column and and write data with particular file used, I have some more column also but I need only 3 column data of first entry after header I attached sample file..those... (12 Replies)
Discussion started by: nex_asp
12 Replies

4. Shell Programming and Scripting

Bash Replace value in specific column

Hi all, I have two files with the following format: file1 BBB;33 AAA;2 CCC;5 file2 5;.;.;. 33;.;.;. The first file contain a list of code and numbers. The second file only the number. I would like to replace the corresponding code in the first column of the file1 with the... (3 Replies)
Discussion started by: g256
3 Replies

5. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

6. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

7. Shell Programming and Scripting

read file line by line print column wise

I have a .csv file which is seperated with (;) inputfile --------- ZZZZ;AAAA;BBB;CCCC;DDD;EEE; YYYY;BBBB;CCC;DDDD;EEE;FFF; ... ... reading file line by line till end of file. while reading each line output format should be . i need to print only specific columns let say 5th... (2 Replies)
Discussion started by: rocking77
2 Replies

8. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

How to read the value from a specific line and column in to a csh variable

Hi All, Although its a basic question the last 2 hours of googling and trying didnt help me to achieve what i want. Maybe some one can help me I have a text file text1.txt: blablablabla A B C D E F and i would like to read to read what is on position E (line 3 column 2) in a... (2 Replies)
Discussion started by: Radamez
2 Replies

10. Shell Programming and Scripting

How to read a specific column into variable

Hi, I want to read the 3rd column of the v_string into a script variable v_3rd, can anyone help howto? v_string="This is for testing only" Thanks! Victor Cheung (2 Replies)
Discussion started by: victorcheung
2 Replies
Login or Register to Ask a Question