Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Awk: use variable defined in begin Post 303009436 by genome on Thursday 14th of December 2017 11:25:57 AM
Old 12-14-2017
NF is going to be constant in a file for all the rows.
A file may have a different number of columns. But they are going to be consistent across all the lines.
I hope I'm making sense.
 

10 More Discussions You Might Find Interesting

1. Linux

environment variable is not defined

moved to correct thread (0 Replies)
Discussion started by: alien12
0 Replies

2. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies

3. Shell Programming and Scripting

Force Input in User Defined Variable

In a line such as: echo -n "How many days back would you like to check? "; read days How can I ensure that the user has a.) entered a number between 1-30 (not 0 or 31+) and b.) has not just hit enter (ie set it to "") and if it's entered wrong, how do I start the if statement over? I... (10 Replies)
Discussion started by: earnstaf
10 Replies

4. Shell Programming and Scripting

Finding Variable Value defined in a Script

Hi , I had a script in which there is a variable $LOG defined and I want to check where that variable is getting value from, is there a way I can check for that variable and it's value if it is defined in some other script function or script . I checked using command env and also export... (1 Reply)
Discussion started by: somu_june
1 Replies

5. Shell Programming and Scripting

Unable to add user defined variable

Hi, I have a user defined variable _TIME1=xxx I am using awk command for pattern matching. cat $_LOCATION/catalina.txt | awk '/^`$_TIME1`:??:??/' It not taking the value of $_TIME! eg:I am using the command to get all the patter from 12:00:00 to 12:59:59 The user defined variable... (2 Replies)
Discussion started by: ahamed
2 Replies

6. UNIX for Dummies Questions & Answers

Finding WHERE an environment variable is defined.

HI. I had an environment variable defined in my .bash_profile file and I deleted it. I opened a new terminal and looked inside .bash_profile and it's not there but when I type printenv MYCONFIG it reutrns what the value used to be in my .bash_profile still!! I did a grep for MYCONFIG and... (6 Replies)
Discussion started by: dissectcode
6 Replies

7. Shell Programming and Scripting

Defined Variable from text file

Hi Guys, I have one text file ABC.txt...It have 3 lines List=/home/klk/dir/ABC.txt Leajnk123 KJUHIO1234 IJOKIJ7676 I want use as different variable of each line.Just like X=firstline Y=Secound Line Z=Third Line (4 Replies)
Discussion started by: asavaliya
4 Replies

8. Shell Programming and Scripting

Question about awk - create a user-defined variable

Hi, guys, The content of file is below (from <UNIX® Shells by Example Fourth Edition>): My code is below: gawk -F'' ' { OFS = "****"; $3 = "(904)"; $8 = $5 + $6 + $7; print } ' lab3.data The result is below: So, where is the $1? Why is the variable $8 located at the wired position? (3 Replies)
Discussion started by: franksunnn
3 Replies

9. Shell Programming and Scripting

How do I get variable defined in BASH subshell outside?

I'm a BASH shell user (relatively new) I need to get a variable calculated in a subshell, outside the subshell, when it completes. I can do it, by writing the variable into a file, and then reading the file again when outside the subshell. I've tried lots of things from exporting to environmental... (3 Replies)
Discussion started by: goreilly
3 Replies

10. Shell Programming and Scripting

Usage of a variable in awk BEGIN

Hi, diffcount=`awk 'BEGIN { while ( getline < "/scripts/matt/text.server1.reference" ) { arr++ } } { if (!( $0 in arr ) ) { print } }' $TMPDIR/$(basename $0 .sh) | wc -l` if ]; then OK="OK - No change in the interfaces status" elif ]; then DIFF=`awk 'BEGIN {... (4 Replies)
Discussion started by: nms
4 Replies
RS(1)							    BSD General Commands Manual 						     RS(1)

NAME
rs -- reshape a data array SYNOPSIS
rs [-[csCS][x] [kKgGw][N] tTeEnyjhHmz] [rows [cols]] DESCRIPTION
The rs utility reads the standard input, interpreting each line as a row of blank-separated entries in an array, transforms the array accord- ing to the options, and writes it on the standard output. With no arguments it transforms stream input into a columnar format convenient for terminal viewing. The shape of the input array is deduced from the number of lines and the number of columns on the first line. If that shape is inconvenient, a more useful one might be obtained by skipping some of the input with the -k option. Other options control interpretation of the input col- umns. The shape of the output array is influenced by the rows and cols specifications, which should be positive integers. If only one of them is a positive integer, rs computes a value for the other which will accommodate all of the data. When necessary, missing data are supplied in a manner specified by the options and surplus data are deleted. There are options to control presentation of the output columns, including transposition of the rows and columns. The following options are available: -cx Input columns are delimited by the single character x. A missing x is taken to be `^I'. -sx Like -c, but maximal strings of x are delimiters. -Cx Output columns are delimited by the single character x. A missing x is taken to be `^I'. -Sx Like -C, but padded strings of x are delimiters. -t Fill in the rows of the output array using the columns of the input array, that is, transpose the input while honoring any rows and cols specifications. -T Print the pure transpose of the input, ignoring any rows or cols specification. -kN Ignore the first N lines of input. -KN Like -k, but print the ignored lines. -gN The gutter width (inter-column space), normally 2, is taken to be N. -GN The gutter width has N percent of the maximum column width added to it. -e Consider each line of input as an array entry. -n On lines having fewer entries than the first line, use null entries to pad out the line. Normally, missing entries are taken from the next line of input. -y If there are too few entries to make up the output dimensions, pad the output by recycling the input from the beginning. Normally, the output is padded with blanks. -h Print the shape of the input array and do nothing else. The shape is just the number of lines and the number of entries on the first line. -H Like -h, but also print the length of each line. -j Right adjust entries within columns. -wN The width of the display, normally 80, is taken to be the positive integer N. -m Do not trim excess delimiters from the ends of the output array. -z Adapt column widths to fit the largest entries appearing in them. With no arguments, rs transposes its input, and assumes one array entry per input line unless the first non-ignored line is longer than the display width. Option letters which take numerical arguments interpret a missing number as zero unless otherwise indicated. EXAMPLES
The rs utility can be used as a filter to convert the stream output of certain programs (e.g., spell, du, file, look, nm, who, and wc(1)) into a convenient ``window'' format, as in % who | rs This function has been incorporated into the ls(1) program, though for most programs with similar output rs suffices. To convert stream input into vector output and back again, use % rs 1 0 | rs 0 1 A 10 by 10 array of random numbers from 1 to 100 and its transpose can be generated with % jot -r 100 | rs 10 10 | tee array | rs -T > tarray In the editor vi(1), a file consisting of a multi-line vector with 9 elements per line can undergo insertions and deletions, and then be neatly reshaped into 9 columns with :1,$!rs 0 9 Finally, to sort a database by the first line of each 4-line field, try % rs -eC 0 4 | sort | rs -c 0 1 SEE ALSO
jot(1), pr(1), sort(1), vi(1) BUGS
Handles only two dimensional arrays. The algorithm currently reads the whole file into memory, so files that do not fit in memory will not be reshaped. Fields cannot be defined yet on character positions. Re-ordering of columns is not yet possible. There are too many options. BSD
December 30, 1993 BSD
All times are GMT -4. The time now is 05:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy