Sponsored Content
Full Discussion: AWK Position Variables
Top Forums Shell Programming and Scripting AWK Position Variables Post 302465565 by Lord Spectre on Friday 22nd of October 2010 07:30:30 PM
Old 10-22-2010
AWK Position Variables


Hello guys,
I'm stuck with AWK and probably stupid stuff. Smilie
I've a file with some values like:
Code:
123 456 10 11 90 39 20 ...........

Then, extracting these vaues from that file is quite simple:
Code:
tail -1 "filename"|awk '{printf $2}'

This will show: 456

Now, what I don't realize is how to do a sequentially extraction using the for cycle:

Code:
for position in 1 2 3 4 5
do
     tail -1 "filename"|awk '{printf ${position}}'
done



The above string is not correct since I receive an error (awk: line 1: syntax error at or near {)

Could someone help me to understand how extracting all values using a for and a position variable ??

Thanks!


Last edited by Scott; 10-23-2010 at 11:46 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using awk removing newline and specific position

Hello Friends, Input File looks as follows: >FASTA Header1 line1 line2 line3 linen >FASTA Header2 Line1 Line2 linen >FASTA Header3 and so on ....... Output: Want something as: >FASTA Header1 line1line2line3linen >FASTA Header2 (5 Replies)
Discussion started by: Deep9000
5 Replies

2. Shell Programming and Scripting

Remove text from n position to n position sed/awk

I want to remove text from nth position to nth position couple of times in same line my line is "hello is there anyone can help me with this question" I need like this ello is there anyone can help me with question 'h' is removed and 'this' removed from the line. I want to do this... (5 Replies)
Discussion started by: elamurugu
5 Replies

3. Shell Programming and Scripting

Position of a string using AWK

I'm plowing through a bunch of text (and I have to use awk) and need to identify which position a certain string is in. Consider the two lines... UP BROADCAST RUNNING SLAVE MULTICAST MTU:1372 Metric:1 UP LOOPBACK RUNNING MTU:16436 Metric:1 I can identify the line by searching for MTU:.... (3 Replies)
Discussion started by: scottwevans
3 Replies

4. Shell Programming and Scripting

Awk Line/Row Position

Hi guys. I'd just like to know if its possible to change the actual line/row position in awk while its busy processing a file. In other words, is it possible to jump from line 10, back up to line 5 and continue processing line-by-line from then onwards? or is the way around this to add all lines... (3 Replies)
Discussion started by: going_grey
3 Replies

5. Shell Programming and Scripting

Help with awk script and update position

Hi, I'm using AIX 5.3 and am trying to get this to work as I need: echo 6078: 6072 6073 6074 6075 6076 6077 6078 6079 | awk '{n=$8} n{sub(n,n+1000000)}1' 1006078: 6072 6073 6074 6075 6076 6077 6078 6079I only want it to change second occurance of 6078 (ie $8) and not the first ($1). I... (4 Replies)
Discussion started by: say170
4 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Find position of character with awk

Hi Guys! Could anyone help me with?.. I have a line which says BCVGF%6$#900 .....How can we know which position is for % or say $ by command or script?There is any way to get a prompt by any script? Thanks a lot (6 Replies)
Discussion started by: Indra2011
6 Replies

7. Shell Programming and Scripting

awk pattern search with inconsistent position

Hi, Anybody knows how to get the value after the regexp and test it on pattern? The if the pattern matches, it will print the entire line on a separate file. Here's my raw file: ^_Name^_string^_Apple ^_Color^_string^_Red ^_Code^_string^_121 ^_Name^_string^_Banana ^_Code^_string^_123 ... (7 Replies)
Discussion started by: Jin_
7 Replies

8. Shell Programming and Scripting

awk usage for position matching

i have a requirement like this if the line contains from position 294 to 299 is equal to "prabhu" ,then print entire line . i want to use awk awk '{if(substr(294-299) == 'prabhu') print "line" }' filename (1 Reply)
Discussion started by: ptappeta
1 Replies

9. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

10. Shell Programming and Scripting

awk Index to get position matches pattern

Input data as below (filetest.txt): 1|22 JAN Minimum Bal 20.00 | SAT 2|09 FEB Extract bal 168.00BR | REM 3|MIN BAL | LEX Output should be: ( If there is Date & Month in 2nd field of Input file, It should be seperated else blank. If There is Decimal OR Decimal & Currency in last of the 2nd... (7 Replies)
Discussion started by: JSKOBS
7 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 12:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy