Operating System - HP-UX
1752800 Members
5694 Online
108789 Solutions
New Discussion юеВ

How do I seperate last 12 charcters in the a output file.

 
Prashant Zanwar_4
Respected Contributor

How do I seperate last 12 charcters in the a output file.

Here I want to seperate
1st whatever number charcters and
just last 12 charcters.
I have a file created by fconfig of EMC, which gives LUN Path followed by frame ID,

I want to seperate the two, they are displayed in joint for right now..
Pls assist
Thx
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: How do I seperate last 12 charcters in the a output file.

Okay I'll take you at your word although I think you mean something else; I assukme the file is at least 12 bytes long:

INFILE=myfile
typeset -i LEN=$(ls -l ${INFILE} | awk '{print $5}')
typeset -i LEN1=$(( ${LEN} - 12 ))
PART1=$(head -c -n ${LEN1} ${INFILE})
PART2=$(tail -c -12 ${INFILE})

echo "Part1 = ${PART1}"
echo "Part2 = ${PART2}"
If it ain't broke, I can fix that.
c_51
Trusted Contributor

Re: How do I seperate last 12 charcters in the a output file.

how about something like this:

cat yourfile | tail -1 |
while read line
do
first=${line%????????????} #12 ?'s
print $first
last12=${line#$first}
print $last12
done
Prashant Zanwar_4
Respected Contributor

Re: How do I seperate last 12 charcters in the a output file.

I wanted to say last 12 per line, not like this..
Thx
Prash
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
c_51
Trusted Contributor

Re: How do I seperate last 12 charcters in the a output file.

then like this:

cat yourfile |
while read line
do
first=${line%????????????} #12 ?'s
last12=${line#$first}
print $last12
done
Hein van den Heuvel
Honored Contributor

Re: How do I seperate last 12 charcters in the a output file.

Why don't you give us a small input + output example ?

for example

C:\temp>type x.txt
aap noot mies123456789012
teun0123456789xx
vuur roosyy1234567890

could solve with awk as:

C:\temp>awk "{l=length($0); print substr($0,1,l-12), substr($0,l-11,12)}" x.txt
aap noot mies 123456789012
teun 0123456789xx
vuur roos yy1234567890

or with sed or perl....

C:\temp>perl -pe "s/(.{12})$/ \1/" x.txt
aap noot mies 123456789012
teun 0123456789xx
vuur roos yy1234567890


is that what you need?
Hein