Hello paranrat,
We obviously have a language barrier that has caused some suggestions being made that do not seem to do what you are trying to do. Your use of the terms character, parameter, front, back, and assign with do not seem to mean the same things that we usually associate with those terms in this forum.
But, except for the example shown in post #14 in this thread (with multiple words on a single input line), it looks like RavinderSingh13's has suggested code that does what you want depending on what version of awk you have available on your system. RavinderSingh13's code depends on the ability to use:
to put each character from an input line into a separate element of the array A[]. This extension works on some versions of awk, but the standards state that the behavior of split() using an empty string as the extended regular expression to be used as the field separator when splitting fields produces unspecified behavior.
The following script allows you to specify the number of leading and trailing characters to be printed along with each character from each of the blank separated words given in the file named file as a command-line operand (defaulting to 2 if no operand is supplied):
If you save this script in a file named tester and make it executable and the file named file contains the text:
then the command ./tester (providing the default 2 characters of context) produces the output:
and the command ./tester 19 (specifying 19 characters of context) produces the output:
Although written and tested using a Korn shell on OS X, this will also work with any other shell that processes POSIX-required parameter expansions. However, if you want to run this on a Solaris/SunOS system, you'll need to change awk in this script to /usr/xpg4/bin/awk or nawk.
Does this meet your needs?
This User Gave Thanks to Don Cragun For This Post:
Hi all,
I am running AIX version 4. I have a shell script that is calling another script. I want the called script to obtain a value and pass it back to the calling script. So far, I know that to pass a parameter to a called script is as such:
sh proc2.sh $1 $2 etc.
What I don't know how... (11 Replies)
I have an HTML form that sends email to a large list of users one at a time by matching an email address in peoplesoft to their username. It works great, except that special characters are converted to %## format. Is there a library of these I can use to sed them back (yes this is a crappy UNIX... (1 Reply)
Say I write something like the following:
var1=1
var2=2
for int in 1 2
do
echo "\$var$int"
done
I want the output to be:
1
2
Instead I get something like:
$var1
$var2 (2 Replies)
Hi every body,
Is it possible to connect two servers Back-to-Back (Point-to-Point) using HBA adapters & using Fiber.
Note it is direct connection & there is no switches between the servers.
I'm concern about using HBA adapters, it is possible or not.
Thanks in advance. :) (3 Replies)
Hi
I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/
Can anyone please help me on this? (3 Replies)
Hi
I read xml files through mq and placed them on unix by using datastage as tool.
I can see some special characters infront of declaration part for every xml file i have produced.
below is the sample snippet when i opened the file by suing vi editor
^Z^E|^A^Z^Z<?xml version="1.0"... (1 Reply)
i am passing input parameter 'one_two' to the script , the script output should display the result as below
one_1two
one_2two
one_3two
if
then
echo " Usage : <$0> <DATABASE> "
exit 0
else
for DB in 1 2 3
do
DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}`
done
fi (5 Replies)
Hello,
I'm trying to write a simple (korn) shell script which is called from the command line with some parameters. But one of the parameter contains a "!" sign. For example: myscript.ksh foo bar foo!bar
When I call the script like above I always get an error. So I tried to wrap the... (1 Reply)
Hi
I have a scenario where hyphen(-) from file should be ignored
I used the following code
if && ; then
if ; then
pow=$LINE
echo $pow > history.txt
flag=1
fi
fi
I get the following output
./valid.sh: -: 0403-012 A test... (7 Replies)