03-16-2016
Quote:
Originally Posted by
RudiC
Using a key outside the range makes sort ignore it and use the entire line for a key which by accident is what you want.
print $5 will print one single field which in the output is field 1 (becoming the default key, then).
You can use another sub (...) to remove the leading path from the file name.
---------- Post updated at 11:09 ---------- Previous update was at 11:08 ----------
You could cd to the working dir, and cd back to the original dir when finished.
So, I should have used
sort -g instead? I tested with that and it worked too.
I know I can cd in and out as I need to. It's not that big of a deal, it's just something I wanted to accomplish with a function.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I am performing a grep command and I need to know how to echo "NONE" or "0" to my file if grep does not find what i am looking for.
echo What i found >> My_File
grep "SOMETHING" >> My_File
I am sure this is easy, I am sort of new at this!
Thanks (2 Replies)
Discussion started by: jojojmac5
2 Replies
2. Shell Programming and Scripting
Hi,
Need awk help to group and print lines to format the output as shown below
INPUT FORMAT
set echo on
set heading on
set spool on
/* SCHEMA1 */ CREATE TABLE T1;
/* SCHEMA1 */ CREATE TABLE T2;
/* SCHEMA1 */ CREATE TABLE T3;
/* SCHEMA1 */ CREATE TABLE T4;
/* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies
3. Shell Programming and Scripting
I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this).
For example, i have a input file1.txt:
cat inputfile1.txt
218299910417
1172051195
1172070231
1172073514
1183135117
1183135118
1183135119
1281440202
... (3 Replies)
Discussion started by: poliver
3 Replies
4. UNIX for Dummies Questions & Answers
hey
i m kinda new to this so i will appreciate any help
, i have this list of values:
pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200
pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300
pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Discussion started by: boaz733
4 Replies
5. Shell Programming and Scripting
Hi,
I have written this code
------------------------------------------------
# !/bin/ksh
i=0
while
do
j=$i
while
do
echo -e $j
#printf "%d",$j
j=`expr $j - 1`
done
echo
i=`expr $i + 1`
done
----------------------------------------------------
The ouput which... (2 Replies)
Discussion started by: rac
2 Replies
6. Shell Programming and Scripting
cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies
7. Shell Programming and Scripting
Dear All,
fileName: therm.txt
nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41
1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2
-2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3
... (7 Replies)
Discussion started by: linuxUser_
7 Replies
8. Shell Programming and Scripting
My code is something like below.
#/bin/bash
for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'`
do
echo $i
ORACLE_SID=`echo $line | awk '{print $2}'`
USERNAME=`echo $line | awk '{print $1}'`
done
=============
But... (3 Replies)
Discussion started by: tapia
3 Replies
9. Shell Programming and Scripting
Hello.
I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas.
I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies
10. Shell Programming and Scripting
Currently using below script but echo it print the output in two line.
Input file all-vm-final-2.txt
CEALA08893 SDDC_SCUN DS_SIO_Workload_SAPUI_UAT_01 4
CEALA09546 SDDC_SCUN DS-SIO-PD5_Workload_UAT_SP1_Flash_07 4
CEALA09702 SDDC_SCUN DS-VSAN-RMP-WORKLOAD01 4
DEALA08762 SDDC_LDC... (3 Replies)
Discussion started by: ranjancom2000
3 Replies
LEARN ABOUT DEBIAN
plan9-sort
SORT(1) General Commands Manual SORT(1)
NAME
sort - sort and/or merge files
SYNOPSIS
sort [ -cmuMbdfinrwtx ] [ +pos1 [ -pos2 ] ... ] ... [ -k pos1 [ ,pos2 ] ] ...
' [ -o output ] [ -T dir ... ] [ option ... ] [ file ... ]
DESCRIPTION
Sort sorts lines of all the files together and writes the result on the standard output. If no input files are named, the standard input
is sorted.
The default sort key is an entire line. Default ordering is lexicographic by runes. The ordering is affected globally by the following
options, one or more of which may appear.
-M Compare as months. The first three non-white space characters of the field are folded to upper case and compared so that precedes
etc. Invalid fields compare low to
-b Ignore leading white space (spaces and tabs) in field comparisons.
-d `Phone directory' order: only letters, accented letters, digits and white space are significant in comparisons.
-f Fold lower case letters onto upper case. Accented characters are folded to their non-accented upper case form.
-i Ignore characters outside the ASCII range 040-0176 in non-numeric comparisons.
-w Like -i, but ignore only tabs and spaces.
-n An initial numeric string, consisting of optional white space, optional plus or minus sign, and zero or more digits with optional
decimal point, is sorted by arithmetic value.
-g Numbers, like -n but with optional e-style exponents, are sorted by value.
-r Reverse the sense of comparisons.
-tx `Tab character' separating fields is x.
The notation +pos1 -pos2 restricts a sort key to a field beginning at pos1 and ending just before pos2. Pos1 and pos2 each have the form
m.n, optionally followed by one or more of the flags Mbdfginr, where m tells a number of fields to skip from the beginning of the line and
n tells a number of characters to skip further. If any flags are present they override all the global ordering options for this key. A
missing .n means .0; a missing -pos2 means the end of the line. Under the -tx option, fields are strings separated by x; otherwise fields
are non-empty strings separated by white space. White space before a field is part of the field, except under option -b. A b flag may be
attached independently to pos1 and pos2.
The notation -k pos1[,pos2] is how POSIX sort defines fields: pos1 and pos2 have the same format but different meanings. The value of m is
origin 1 instead of origin 0 and a missing .n in pos2 is the end of the field.
When there are multiple sort keys, later keys are compared only after all earlier keys compare equal. Lines that otherwise compare equal
are ordered with all bytes significant.
These option arguments are also understood:
-c Check that the single input file is sorted according to the ordering rules; give no output unless the file is out of sort.
-m Merge; assume the input files are already sorted.
-u Suppress all but one in each set of equal lines. Ignored bytes and bytes outside keys do not participate in this comparison.
-o The next argument is the name of an output file to use instead of the standard output. This file may be the same as one of the
inputs.
-Tdir Put temporary files in dir rather than in /var/tmp.
EXAMPLES
Print in alphabetical order all the unique spellings
in a list of words where capitalized words differ from uncapitalized.
Print the users file
sorted by user name (the second colon-separated field).
Print the first instance of each month in an already sorted file.
Options -um with just one input file make the choice of a unique representative from a set of equal lines predictable.
grep -n '^' input | sort -t: +1f +0n | sed 's/[0-9]*://'
A stable sort: input lines that compare equal will come out in their original order.
FILES
/var/tmp/sort.<pid>.<ordinal>
SOURCE
/src/cmd/sort.c
SEE ALSO
uniq(1), look(1)
DIAGNOSTICS
Sort comments and exits with non-null status for various trouble conditions and for disorder discovered under option -c.
BUGS
An external null character can be confused with an internally generated end-of-field character. The result can make a sub-field not sort
less than a longer field.
Some of the options, e.g. -i and -M, are hopelessly provincial.
SORT(1)