The trouble with manipulation of NF is that its effect is not specified by POSIX, so if there is an effect, it is implementation-specific.
So I think in awk the regex route is the most reliable way, or removing the last field and field separator, so:
(which is analogous to MadeinGermany's sed suggestion) or
With sed:
GNU sed -r or BSD sed -E :
--
Hi Don, that works with nawk, but it does not appear to work with /usr/xpg4/bin/awk .
I have not come across /usr/xpg6/bin/awk is that part of Solaris 11 or is that available as part of an additional package?
Hi Scrutinizer,
Thanks for the information. I no longer have access to a Solaris system to test these types of things. I didn't realize there was a difference in the way NF was handled in nawk and /usr/xpg[46]/awk. (One key difference between the three is which shell is used when you use the awk system() function (/bin/sh, /usr/xpg4/bin/sh, or /usr/xpg6/bin/sh, respectively)). The Solaris nawk comes straight from the AT&T newawk from the 1980's. I don't remember where the base source for /usr/xpg[46]/bin/awk came from.
The /usr/xpg6 hierarchy should be available on any Solaris system released since about 2004 or 2005, but it may have been an install time option rather than part of the default install.
The code I suggested works on OS X, so it probably works on BSD derived versions of awk. (And, this isn't surprising since the newawk came out of AT&T's Research UNIX group rather than AT&T's Programmer's Workbench UNIX group.)
Hi,
This is my input file:
ali 5 usa abc
abu 4 uk bca
alan 6 brazil bac
pinky 10 utah sdc
My desired output:
pinky 10 utah sdc
alan 6 brazil bac
ali 5 usa abc
abu 4 uk bca
Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Hi. How do I find an expression with awk in only one column, and if it fits, then print that whole column.
1 apple oranges
2 bannanas pears
3 cats dogs
4 hesaid shesaid
echo "which number:"
read NUMBER (user inputs number 2 for this example)
awk " /$NUMBER/ {field to search is field... (2 Replies)
Hi friends,
My file is like:
Second file is :
I need to print the rows present in file one, but in order present in second file....I used
while read gh;do
awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile
done < secondfile
but the output I am... (14 Replies)
Dear All,
I have a data file input.csv like below. (Only five column shown here for example.)
Data1,StepNo,Data2,Data3,Data4
2,1,3,4,5
3,1,5,6,7
3,2,4,5,6
5,3,5,5,6
From this I want the below output
Data1,StepNo,Data2,Data3,Data4
2,1,3,4,5
3,1,5,6,7
where the second column... (4 Replies)
Hi,
My input files is like this
axis1 0 1 10
axis2 0 1 5
axis1 1 2 -4
axis2 2 3 -3
axis1 3 4 5
axis2 3 4 -1
axis1 4 5 -6
axis2 4 5 1
Now, these are my following tasks
1. Print a first column for every two rows that has the same value followed by a string.
2. Match on the... (3 Replies)
Input file :
5 20
500 2
20 41
41 0
23 1
Desired output :
5
2
20
0
1
By comparing column 1 and 2 in each line, I hope can print out the column with smallest number.
I did try the following code, but it don't look good :( (2 Replies)
Input file:
2
10
15
20
24
Output file
2 8 NNNNNNNN
10 5 NNNNN
15 5 NNNNN
20 4 NNNN
24
Do anybody experience subtraction column by column and print out number of subtraction times with N?
The second column of the output file is the subtraction of 10-2 = 8; The third column just... (3 Replies)
Example:
I have files in below format
file 1:
zxc,133,joe@example.com
cst,222,xyz@example1.com
File 2 Contains:
hxd
hcd
jws
zxc
cst
File 1 has 50000 lines and file 2 has around 30000 lines :
Expected Output has to be :
hxd
hcd
jws (5 Replies)