Sponsored Content
Top Forums Shell Programming and Scripting how to print field n of line m Post 302246482 by Deanne on Monday 13th of October 2008 08:31:46 PM
Old 10-13-2008
thanks franklin! will try it!

oh im using the default field separator (space) Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print empty line when the a field is changed

Hi all, I have this input file .. BSS01 107 Swafieh 11/06/2008 12:06:57 BSS01 111 Ramada_Hotel 12/06/2008 11:37:20 BSS01 147 Kalha_Rep 11/06/2008 19:13:39 BSS01 147 Kalha_Rep ... (9 Replies)
Discussion started by: yahyaaa
9 Replies

2. Shell Programming and Scripting

Print line if first Field matches a pattern

Hi All, I would like my code to be able to print out the whole line if 1st field has a dot in the number. Sample input and expected output given below. My AWK code is below but it can;t work, can any expert help me ? Thanks in advance. {if ($1 ~ /*\.*/) { print $0 }} Input: ... (2 Replies)
Discussion started by: Raynon
2 Replies

3. Shell Programming and Scripting

Print the entire line if second field has value P

Friends, I have .txt file with 3 millions of rows. File1.txt ABC1|A|ABCD1|XYZ1 ABC2|P|ABCD2|XYZ2 ABC3|A|ABCD3|XYZ3 ABC4|P|ABCD4|XYZ4 If second field has value P then print the entire line. Thanks in advance for your help, Prashant (4 Replies)
Discussion started by: ppat7046
4 Replies

4. Shell Programming and Scripting

How to print line if field matches?

Hi all, I got several lines line this a b c d e 1 e a 1 c d e 3 f a b c 1 e 8 h a b c d e 1 w a 1 c d e 2 w a b c d e 1 t a b c d e 7 4 How can I print the line if 1 is the field one before the last field? Basicly this 2 field ? a b c d e 1 e a b c d e 1 t The file I got is... (7 Replies)
Discussion started by: stinkefisch
7 Replies

5. UNIX for Advanced & Expert Users

print line backwards - horizontally by field?

let's say you have dog, cat, 1, 2, 3 reverse, 7, 9, i, tell, you you want to print 3, 2, 1, cat, dog you, tell, i, 9, 7, reverse The delimiter is a comma. The number of commas in each line though is undetermined. How would you do this using either regular UNIX or awk? I know the... (5 Replies)
Discussion started by: Josef_Stalin
5 Replies

6. Shell Programming and Scripting

only print line if 3rd field is 01

Similar question... I have a space delimited text file and I want to only print the lines where the 3rd word/field/column is equal to "01" awk '{if $3 = "01" print $0}' something like this. I meant to say: only print line IF 3rd field is 01 (2 Replies)
Discussion started by: ajp7701
2 Replies

7. Shell Programming and Scripting

Print a field from the previous line

plz help me!! I have this file , 3408 5600 3796 6035 4200 6285 4676 0 40 1554 200 1998 652 2451 864 2728 1200 0 I want it like if $2==0,replace it with field from the previous line+500 say here the o/p would be like 3408 5600 3796 6035 4200 6285... (16 Replies)
Discussion started by: Indra2011
16 Replies

8. Shell Programming and Scripting

print whole line if the 1st field contains...

i want to print lines in a file that the 1st field of each line has a Date shape such: yy/mm/dd or on the other hand contains slash "/" . (1 Reply)
Discussion started by: oreka18
1 Replies

9. Shell Programming and Scripting

Use two field separator in the same line and print them

Hi Guys, I have the file --- HOST_NAME,data_coleta,data_carga,CPU_util,CPU_idle,run_queue,memory,MEMORY_SYSTEM,MEMORY_TOTAL,MEMORY_SWAPIN,MEMORY_SWAPOUT,DISK_READ,DISK_WRITE,DISK_IO,NET_IN_PACKET, NET_OUT_PACKET... (4 Replies)
Discussion started by: antoniorajr
4 Replies

10. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies
SORT(1) 						    BSD General Commands Manual 						   SORT(1)

NAME
sort -- sort or merge text files SYNOPSIS
sort [-bcdfHilmnrSsu] [-k field1[,field2]] [-o output] [-R char] [-T dir] [-t char] [file ...] DESCRIPTION
The sort utility sorts text files by lines. Comparisons are based on one or more sort keys extracted from each line of input, and are per- formed lexicographically. By default, if keys are not given, sort regards each input line as a single field. The following options are available: -c Check that the single input file is sorted. If the file is not sorted, sort produces the appropriate error messages and exits with code 1; otherwise, sort returns 0. sort -c produces no output. -H Ignored for compatibility with earlier versions of sort. -m Merge only; the input files are assumed to be pre-sorted. -o output The argument given is the name of an output file to be used instead of the standard output. This file can be the same as one of the input files. -S Don't use stable sort. Default is to use stable sort. -s Use stable sort, keeps records with equal keys in their original order. This is the default. Provided for compatibility with other sort implementations only. -T dir Use dir as the directory for temporary files. The default is the value specified in the environment variable TMPDIR or /tmp if TMPDIR is not defined. -u Unique: suppress all but one in each set of lines having equal keys. If used with the -c option, check that there are no lines with duplicate keys. The following options override the default ordering rules. When ordering options appear independent of key field specifications, the requested field ordering rules are applied globally to all sort keys. When attached to a specific key (see -k), the ordering options over- ride all global ordering options for that key. -d Only blank space and alphanumeric characters are used in making comparisons. -f Considers all lowercase characters that have uppercase equivalents to be the same for purposes of comparison. -i Ignore all non-printable characters. -l Sort by the string length of the field, not by the field itself. -n An initial numeric string, consisting of optional blank space, optional minus sign, and zero or more digits (including decimal point) is sorted by arithmetic value. (The -n option no longer implies the -b option.) -r Reverse the sense of comparisons. The treatment of field separators can be altered using these options: -b Ignores leading blank space when determining the start and end of a restricted sort key. A -b option specified before the first -k option applies globally to all -k options. Otherwise, the -b option can be attached independently to each field argument of the -k option (see below). Note that the -b option has no effect unless key fields are specified. -t char char is used as the field separator character. The initial char is not considered to be part of a field when determining key offsets (see below). Each occurrence of char is significant (for example, ``charchar'' delimits an empty field). If -t is not specified, the default field separator is a sequence of blank-space characters, and consecutive blank spaces do not delimit an empty field; further, the initial blank space is considered part of a field when determining key offsets. -R char char is used as the record separator character. This should be used with discretion; -R <alphanumeric> usually produces undesir- able results. The default record separator is newline. -k field1[,field2] Designates the starting position, field1, and optional ending position, field2, of a key field. The -k option replaces the obso- lescent options +pos1 and -pos2. The following operands are available: file The pathname of a file to be sorted, merged, or checked. If no file operands are specified, or if a file operand is -, the standard input is used. A field is defined as a minimal sequence of characters followed by a field separator or a newline character. By default, the first blank space of a sequence of blank spaces acts as the field separator. All blank spaces in a sequence of blank spaces are considered as part of the next field; for example, all blank spaces at the beginning of a line are considered to be part of the first field. Fields are specified by the -k field1[,field2] argument. A missing field2 argument defaults to the end of a line. The arguments field1 and field2 have the form m.n and can be followed by one or more of the letters b, d, f, i, l, n, and r, which correspond to the options discussed above. A field1 position specified by m.n (m, n > 0) is interpreted as the nth character in the mth field. A miss- ing .n in field1 means '.1', indicating the first character of the mth field; if the -b option is in effect, n is counted from the first non- blank character in the mth field; m.1b refers to the first non-blank character in the mth field. A field2 position specified by m.n is interpreted as the nth character (including separators) of the mth field. A missing .n indicates the last character of the mth field; m = 0 designates the end of a line. Thus the option -k v.x,w.y is synonymous with the obsolescent option +v-1.x-1-w-1.y; when y is omitted, -k v.x,w is synonymous with +v-1.x-1-w+1.0. The obsolescent +pos1 -pos2 option is still supported, except for -w.0b, which has no -k equivalent. ENVIRONMENT
If the following environment variable exists, it is used by sort. TMPDIR sort uses the contents of the TMPDIR environment variable as the path in which to store temporary files. FILES
/tmp/sort.* Default temporary files. outputNUMBER Temporary file which is used for output if output already exists. Once sorting is finished, this file replaces output (via link(2) and unlink(2)). EXIT STATUS
Sort exits with one of the following values: 0 Normal behavior. 1 On disorder (or non-uniqueness) with the -c option 2 An error occurred. SEE ALSO
comm(1), join(1), uniq(1), qsort(3), radixsort(3) HISTORY
A sort command appeared in Version 5 AT&T UNIX. This sort implementation appeared in 4.4BSD and is used since NetBSD 1.6. BUGS
Posix requires the locale's thousands separator be ignored in numbers. It may be faster to sort very large files in pieces and then explic- itly merge them. NOTES
This sort has no limits on input line length (other than imposed by available memory) or any restrictions on bytes allowed within lines. To protect data sort -o calls link(2) and unlink(2), and thus fails on protected directories. Input files should be text files. If file doesn't end with record separator (which is typically newline), the sort utility silently supplies one. The current sort uses lexicographic radix sorting, which requires that sort keys be kept in memory (as opposed to previous versions which used quick and merge sorts and did not.) Thus performance depends highly on efficient choice of sort keys, and the -b option and the field2 argument of the -k option should be used whenever possible. Similarly, sort -k1f is equivalent to sort -f and may take twice as long. BSD
December 18, 2010 BSD
All times are GMT -4. The time now is 08:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy