Sponsored Content
Top Forums Shell Programming and Scripting To test whether a field contains string value Post 303003900 by ctsgnb on Friday 22nd of September 2017 11:09:56 AM
Old 09-22-2017
Please provide an example of representative input file, field, field separator, and by the way, what did you try so far ?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

string test?

hey guys- what is the syntax for a string test to verify that a user has entered a 6 digit numeric? Thanks for your help in advance! Todd (9 Replies)
Discussion started by: hedrict
9 Replies

2. UNIX for Dummies Questions & Answers

test a string...

Hi! I'm using echo $string | grep "" -c to test in a script if a string is a number and it seems to work. But how can i find, for example, if a string is a four figures number ? Thanks to all! (2 Replies)
Discussion started by: Kaminski
2 Replies

3. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

4. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

5. Shell Programming and Scripting

string test in IF statement

How do I test multiple words in a string test like below: if ] then print "You entered $TBS name.\n" else print "You entered an incorrect response.\n" fi This test does not work. I have tried different syntax versions. How does this work? And is there a better way to do it? ... (10 Replies)
Discussion started by: djehresmann
10 Replies

6. Shell Programming and Scripting

Awk Search text string in field, not all in field.

Hello, I am using awk to match text in a tab separated field and am able to do so when matching the exact word. My problem is that I would like to match any sequence of text in the tab-separated field without having to match it all. Any help will be appreciated. Please see the code below. awk... (3 Replies)
Discussion started by: rocket_dog
3 Replies

7. Shell Programming and Scripting

string test

How do I use bash to test if a line begins with a random number of spaces followed by a letter? (1 Reply)
Discussion started by: locoroco
1 Replies

8. Shell Programming and Scripting

test for a blank string

Hi guys I am performing a simple test for a blank string with the following code: if ] ]] ; then echo "Blanks are NOT a valid input " return 1 fi The above fails giving a syntax error message: syntax error at line 142 : `=~' unexpected I am in ksh88 is there... (2 Replies)
Discussion started by: aoussenko
2 Replies

9. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

10. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies
sort5(1)						      General Commands Manual							  sort5(1)

Name
       sort5 - internationalized System 5 sort and/or merge files

Syntax
       sort5 [-cmu] [-ooutput] [-ykmem] [-zrecsz] [-X] [-dfiMnr] [-btx] [+pos1 [-pos2]] [files]

Description
       The  command  sorts lines of the named files together and writes the result on the standard output.  The standard input is read if a hyphen
       (-) is used as a file name or if no input files are named.

       Comparisons are based on one or more sort keys extracted from each line of input.  By default, there is one  sort  key,	the  entire  input
       line,  and  ordering is determined by the collating sequence specified by the LC_COLLATE locale. The LC_COLLATE locale is controlled by the
       settings of either the LANG or LC_COLLATE environment variables. See for more information.

Options
       The following options alter the default behavior:

       -c   Checks that the input file is sorted according to the ordering rules; gives no output unless the file is out of order.

       -m   Merges only; the input files are already sorted.

       -u   Suppresses all but one in each set of lines having equal keys.

       -ooutput
	    Specifies the name of an output file to use instead of the standard output.  The file may be the same as one of  the  inputs.   Blanks
	    between -o and output are optional.

       -ykmem
	    Specifies  the  number  of	kilobytes  of  memory  to use when sorting a file.  If this option is omitted, sort5 begins using a system
	    default memory size, and continues to use more space as needed.  If kmem is specified, sort5 starts using that number of kilobytes	of
	    memory.   If  the administrative minimum or maximum is violated, the value of the corresponding minimum or maximum is used.  Thus, -y0
	    is guaranteed to start with minimum memory.  By convention, -y (with no argument) starts with maximum memory.

       -zrecsz
	    Records the size of the longest line read in the sort phase so buffers can be allocated during the merge phase.  If the sort phase	is
	    omitted using either the -c or -m options, a system default size is used.  Lines longer than the buffer size cause to terminate abnor-
	    mally.  Supplying the actual number of bytes (or some larger value) in the longest line to be merged prevents abnormal termination.

       -X   Sorts using tags. Upon input each key is converted to a tag value which is sorted efficiently. This option makes international sorting
	    faster but it consumes more memory since both key and tag must be stored.

       The following options override the default ordering rules:

       -d   Specifies Dictionary order.  Only letters, digits and blanks (spaces and tabs) are significant in comparisons.

       -f   Folds lower case letters into upper case.

       -i   Ignores characters outside the ASCII range 040-0176 in non-numeric comparisons.

       -n   Sorts  an  initial	numeric  string, consisting of optional blanks, optional minus sign, and zero or more digits with optional decimal
	    point, by arithmetic value.  The -n option implies the -b option, which tells the command to ignore leading  blanks  when  determining
	    the starting and ending positions of a restricted sort key.

       -r   Reverses the sense of comparisons.

       When ordering options appear before restricted sort key specifications, the requested ordering rules are applied globally to all sort keys.
       When attached to a specific sort key (described below), the specified ordering options override all global ordering options for that key.

       The notation +pos1 -pos2 restricts a sort key to one beginning at pos1 and ending at pos2.  The characters at positions pos1 and  pos2  are
       included in the sort key (provided that pos2 does not precede pos1).  A missing -pos2 means the end of the line.

       Specifying  pos1  and pos2 involves the notion of a field, that is a minimal sequence of characters followed by a field separator or a new-
       line.  By default, the first blank of a sequence of blanks acts as the field separator.	The blank can be either a space  or  a	tab.   All
       blanks  in a sequence of blanks are interpreted as a part of the next field; for example, all blanks at the beginning of a line are consid-
       ered to be part of the first field.  The treatment of field separators is altered using the following options:

       -tx  Uses x as the field separator character.  Although it may be included in a sort key, x is not considered part of a field.  Each occur-
	    rence of x is significant (for example, xx delimits an empty field).

       -b   Ignores  leading  blanks  when  determining the starting and ending positions of a restricted sort key.  If the -b option is specified
	    before the first +pos1 argument, it is applied to all +pos1 arguments.  Otherwise, the b flag may be attached  independently  to  each
	    +pos1 or -pos2 argument.

       Pos1  and  pos2	each  have  the form m.n optionally followed by one or more of the flags bdfinr.  A starting position specified by +m.n is
       interpreted to mean the n+1st character in the m+1st field.  A missing .n means .0, indicating the first character of the m+1st field.	If
       the  b  flag  is  in  effect n is counted from the first non-blank in the m+1st field; +m.0b refers to the first non-blank character in the
       m+1st field.

       A last position specified by -m.n is interpreted to mean the nth character (including separators) after the last  character  of	the  m	th
       field.  A missing .n means .0, indicating the last character of the mth field.  If the b flag is in effect n is counted from the last lead-
       ing blank in the m+1st field; -m.1b refers to the first non-blank in the m+1st field.

       When there are multiple sort keys, later keys are compared only after all earlier keys are found to be equal.  Lines that otherwise compare
       equal are ordered with all bytes significant.

Examples
       Sort the contents of infile with the second field as the sort key:

	      sort5 +1 -2 infile

       Sort,  in  reverse  order,  the	contents of infile1 and infile2, placing the output in outfile and using the first character of the second
       field as the sort key:

	      sort5 -r -o outfile +1.0 -1.2 infile1 infile2

       Sort, in reverse order, the contents of infile1 and infile2 using the first non-blank character of the second field as the sort key:

	      sort5 -r +1.0b -1.1b infile1 infile2

       Print the password file sorted by the numeric user ID (the third colon-separated field):

	      sort5 -t: +2n -3 /etc/passwd

       Print the lines of the already sorted file infile, suppressing all but the first occurrence of lines  having  the  same	third  field  (the
       options -um with just one input file make the choice of a unique representative from a set of equal lines predictable):

	      sort5 -um +2 -3 infile

Diagnostics
       Comments  and exits with non-zero status for various trouble conditions (for example, when input lines are too long), and for disorder dis-
       covered under the -c option.

       When the last line of an input file is missing a new-line character, sort5 appends one, prints a warning message, and continues.

Files
       /usr/tmp/stm???

See Also
       comm(1), join(1), uniq(1), setlocale(3int), strcoll(3int)

																	  sort5(1)
All times are GMT -4. The time now is 09:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy