I a file with log entries... I want to sort it so that the last line in the file is first and the first line is last..
eg.
Sample file
1
h
a
f
8
6
After sort should look like
6
8
f
a
h
1 (11 Replies)
I need to sort the particular column only in reverse order how i can give it..
if i give the -r option the whole file is getting sorted in reverse order.
1st 2nd col 3rd
C col 4th col 5th col
-------------------------------------------
C... (7 Replies)
Hi Everyone,
I have one a.txt:
a b 001 c
b b 002 c
c c, not 002 c
The output should be
001
002
002
If i use cut -f 3 -d' ', this does not work on the 3rd line, so i thought is any way to cut the field counting from the end? or any perl thing can do this?:confused:
... (3 Replies)
Hi, Guys. Please help me to find solution to this problem using shell scripting.
I have an INPUT file with 4 columns separated by tab. Each block of records is separated by -----
-----
Sample1 5402 6680 Pattern01
Sample2 2216 2368 Pattern02... (6 Replies)
command/script(apart from awk) to print the fields in reverse order
that is last field has to come first and so on and first field has to go last
Input
store-id date sale
.............
.............
... (3 Replies)
Hi,
I want to print the item in reverse order such that the output would look like
00 50 50 23 40 22 02 96
Below is the input:
00 05 05 32 04 22 20 69
Video tutorial on how to use code tags in The UNIX and Linux Forums. (5 Replies)
I have a unix script that outputs a summary file to the mac desktop.
The file is called summary.txt
I am trying to configure such so that the summary.txt file lists the content contained within such in reverse sort order.
I have used sort -r but it does not seem to work.
I would be... (8 Replies)
Discussion started by: Braveheart
8 Replies
LEARN ABOUT MOJAVE
getopt
GETOPT(1) BSD General Commands Manual GETOPT(1)NAME
getopt -- parse command options
SYNOPSIS
args=`getopt optstring $*` ; errcode=$?; set -- $args
DESCRIPTION
The getopt utility is used to break up options in command lines for easy parsing by shell procedures, and to check for legal options.
Optstring is a string of recognized option letters (see getopt(3)); if a letter is followed by a colon, the option is expected to have an
argument which may or may not be separated from it by white space. The special option '--' is used to delimit the end of the options. The
getopt utility will place '--' in the arguments at the end of the options, or recognize it if used explicitly. The shell arguments ($1 $2
...) are reset so that each option is preceded by a '-' and in its own shell argument; each option argument is also in its own shell argu-
ment.
EXAMPLES
The following code fragment shows how one might process the arguments for a command that can take the options -a and -b, and the option -o,
which requires an argument.
args=`getopt abo: $*`
# you should not use `getopt abo: "$@"` since that would parse
# the arguments differently from what the set command below does.
if [ $? != 0 ]
then
echo 'Usage: ...'
exit 2
fi
set -- $args
# You cannot use the set command with a backquoted getopt directly,
# since the exit code from getopt would be shadowed by those of set,
# which is zero by definition.
for i
do
case "$i"
in
-a|-b)
echo flag $i set; sflags="${i#-}$sflags";
shift;;
-o)
echo oarg is "'"$2"'"; oarg="$2"; shift;
shift;;
--)
shift; break;;
esac
done
echo single-char flags: "'"$sflags"'"
echo oarg is "'"$oarg"'"
This code will accept any of the following as equivalent:
cmd -aoarg file file
cmd -a -o arg file file
cmd -oarg -a file file
cmd -a -oarg -- file file
SEE ALSO sh(1), getopt(3)DIAGNOSTICS
The getopt utility prints an error message on the standard error output and exits with status > 0 when it encounters an option letter not
included in optstring.
HISTORY
Written by Henry Spencer, working from a Bell Labs manual page. Behavior believed identical to the Bell version. Example changed in FreeBSD
version 3.2 and 4.0.
BUGS
Whatever getopt(3) has.
Arguments containing white space or embedded shell metacharacters generally will not survive intact; this looks easy to fix but isn't. Peo-
ple trying to fix getopt or the example in this manpage should check the history of this file in FreeBSD.
The error message for an invalid option is identified as coming from getopt rather than from the shell procedure containing the invocation of
getopt; this again is hard to fix.
The precise best way to use the set command to set the arguments without disrupting the value(s) of shell options varies from one shell ver-
sion to another.
Each shellscript has to carry complex code to parse arguments halfway correcty (like the example presented here). A better getopt-like tool
would move much of the complexity into the tool and keep the client shell scripts simpler.
BSD April 3, 1999 BSD