08-20-2009
reverse ':' separated numbers in a shell script
I want to reverse a the following:
00:11:22:33:44:55
I currently use something like below to pass it as is.
But now I want the same script to reverse the above and pass it to ethtool.
// psuedo code
i=0
skip=0
for m in $@
do
if [ $skip -eq 0 ]
then
skip=1
for b in $(echo $m | tr ':' ' ')
do
ethtool -E eth$i offset $c value 0x$b
c=$(($c + 1))
done
else
skip=0
fi
i=$(($i + 1))
done
echo "OK"
Thank you
- bhan
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello everybody !
GOT SOMETHING INTERESTING...
I am trying to retain line number for a text document.. usually we get line numbers in VI using :set nu , but I want to permanently store them. It's a 4000 lines of text and I want grep/search it for a list of words/fields stored in a different... (2 Replies)
Discussion started by: sdlayeeq
2 Replies
2. Shell Programming and Scripting
cat dailyreports | grep "Important list" | awk -F":" '{print $2}' | awk -F" " '{print $1}'
hey guys, after running the above combination of cat and awk, i get the below output:
3
4
2
9
now, i need to add these numbers up all in one line. i dont know what to add to that cat and awk one... (2 Replies)
Discussion started by: Terrible
2 Replies
3. Shell Programming and Scripting
Dear All,
I have a comma-separated file.
1. The first line of the file(header) should have 4 commas(5 fields).
2. The last line of the file should have 1 comma(2 fields).
Pls help me in checking this condition in a shell script.
And the number of lines between the first line and last... (11 Replies)
Discussion started by: KrishnaSaran
11 Replies
4. Shell Programming and Scripting
Hi,
this is fantastic forum for shell programming and scripting,
so please let me to introduce you with my very old concept to
have web form/s with radio, select, input fields
and have an application generating valid, syntax error free scripting code.
The same or alike questions are asked... (2 Replies)
Discussion started by: darius2
2 Replies
5. UNIX for Dummies Questions & Answers
Hi,
I have a requirement wherein, I need to validate a user input of the numbers that are comma separated.
E.g . The input should be in the format 1,2,3...n (count of numbers is not known) . The user has to mention the input in this format, else it should exit from the program.
... (5 Replies)
Discussion started by: 12345
5 Replies
6. Shell Programming and Scripting
Hello All,
I have 3 types of files. The names of which starts with P,I,M
like P*********
D*********
M*********
now I need to do some operations witht hese files..
so
if file name starts with P or p
then
do the operation for P file...
fi
else (20 Replies)
Discussion started by: smarty86
20 Replies
7. Shell Programming and Scripting
file A
E969K
D223L
E400L
E34L
file B
predicted 3
1 250
251 500
501 1000
The output should be
E969K 501 1000
D223L 1 250
E400L 251 500
E34L 1 250
I tried in this way (1 Reply)
Discussion started by: cdfd123
1 Replies
8. Shell Programming and Scripting
Hi,
In shell script, I have a variable var = xyz, inn, day, night, calif ....n and I would like to read them in to var1 = xzy, var2 = inn, var3= day, var4 = night....var.
probably in a loop. I would like to read the variables until end of the line. Comma is the delimiter and there's no comma at... (3 Replies)
Discussion started by: suryaemlinux
3 Replies
9. Shell Programming and Scripting
Hi all
i have a data of this form
10.12.4.22:138
10.12.2.50:137
10.20.2.24:1027
10.12.2.44:138
10.12.2.44:137
10.0.4.38:58871
10.13.3.19:138
i need to separate the number out which is at the last and after ':'
Please help me out
Thanx in advance (5 Replies)
Discussion started by: vaibhavkorde
5 Replies
10. Shell Programming and Scripting
Hi,
I am trying to create a shell script in unix platform, hence will need info on how to start and any ideas from you guys. million thx.
Objective: Shell script to search all entries from 1 file(a.out) to all other files and extract the search output to 1 file (c.out).
Situation,
1)... (8 Replies)
Discussion started by: Mr_47
8 Replies
LEARN ABOUT LINUX
run-parts
RUN-PARTS(8) System Manager's Manual RUN-PARTS(8)
NAME
run-parts - run scripts or programs in a directory
SYNOPSIS
run-parts [--test] [--verbose] [--report] [--lsbsysinit] [--regex=RE] [--umask=umask] [--arg=argument] [--exit-on-error] [--help] [--ver-
sion] [--list] [--reverse] [--] DIRECTORY
run-parts -V
DESCRIPTION
run-parts runs all the executable files named within constraints described below, found in directory directory. Other files and directo-
ries are silently ignored.
If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case let-
ters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.
If the --lsbsysinit option is given, then the names must not end in .dpkg-old or .dpkg-dist or .dpkg-new or .dpkg-tmp, and must belong to
one or more of the following namespaces: the LANANA-assigned namespace (^[a-z0-9]+$); the LSB hierarchical and reserved namespaces
(^_?([a-z0-9_.]+-)+[a-z0-9]+$); and the Debian cron script namespace (^[a-zA-Z0-9_-]+$).
If the --regex option is given, the names must match the custom extended regular expression specified as that option's argument.
Files are run in the lexical sort order of their names unless the --reverse option is given, in which case they are run in the opposite
order.
OPTIONS
--test print the names of the scripts which would be run, but don't actually run them.
--list print the names of the all matching files (not limited to executables), but don't actually run them. This option cannot be used with
--test.
-v, --verbose
print the name of each script to stderr before running.
--report
similar to --verbose, but only prints the name of scripts which produce output. The script's name is printed to whichever of stdout
or stderr the script first produces output on.
--reverse
reverse the scripts' execution order.
--exit-on-error
exit as soon as a script returns with a non-zero exit code.
--lsbsysinit
use LSB namespaces instead of classical behavior.
--new-session
run each script in a separate process session. If you use this option, killing run-parts will not kill the currently running
script, it will run until completion.
--regex=RE
validate filenames against custom extended regular expression RE. See the EXAMPLES section for an example.
-u, --umask=umask
sets the umask to umask before running the scripts. umask should be specified in octal. By default the umask is set to 022.
-a, --arg=argument
pass argument to the scripts. Use --arg once for each argument you want passed.
-- specifies that this is the end of the options. Any filename after -- will be not be interpreted as an option even if it starts with
a hyphen.
-h, --help
display usage information and exit.
-V, --version
display version and copyright and exit.
EXAMPLES
Print the names of all files in /etc that start with `p' and end with `d':
run-parts --list --regex '^p.*d$' /etc
COPYRIGHT
Copyright (C) 1994 Ian Jackson.
Copyright (C) 1996 Jeff Noxon.
Copyright (C) 1996, 1997, 1998 Guy Maor
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Clint Adams
run-parts is free software; see the GNU General Public License version 2 or later for copying conditions. There is no warranty.
Debian 14 Nov 2010 RUN-PARTS(8)