Sponsored Content
Full Discussion: Variable usage issue
Top Forums UNIX for Dummies Questions & Answers Variable usage issue Post 302843015 by Prem148 on Sunday 11th of August 2013 04:27:30 PM
Old 08-11-2013
Variable usage issue

Hi,

I need a help in setting scope of the variable. I want to use the below logic right before the "break" statement
Code:
if [ ${trailer} -eq $eof ]; then
echo $header
echo $trailer
fi

But due the scope of the variable it is causing issues. I tried using "export" statement. But it changes the output completely
Code:
#!/bin/sh
file="drop/test1"
filename="2154/drop/abc.emi"
eof=`wc -l $filename | awk '{print $1;}'`
blk_val=99999
while read j
do
prev=$j
prev1=$j
blk_flag=0
loop_count=0
blk_size=0
while read j
do
 if [ ${j} -gt ${prev} ]; then
 next=$j
 blk_size=`expr $next - $prev + $blk_size + 1 `
	 if [ ${blk_size} -ge ${blk_val} ]; then
		 if [ ${blk_flag} -eq 1 ]; then
			    if [ ${loop_count} -eq 0 ]; then
				 header=$prev1
				 trailer=$next
				 prev=`expr $next + 1`
				 echo h0=$header
				 echo t0=$trailer
				 blk_size=0
				 blk_flag=0
				 loop_count=1
				 prev1=`expr $trailer + 1`
			    else 
				 prev1=`expr $trailer + 1`
				 trailer=$next
				 prev=`expr $next + 1`
				 header=$prev1
				 echo h1=$header
				 echo t1=$trailer
				 blk_size=0
				 blk_flag=0
			    fi	 
		 else 
			 header=$prev
			 trailer=$next
			 prev=`expr $next + 1`
			 blk_size=0
			 blk_flag=0
			 echo h2=$header
			 echo t2=$trailer 	        
		 fi	 
	 else
		 prev=`expr $next + 1`
		 blk_flag=1
	 fi	

 fi
done < $file      
break
done < $file

I/P file is a big file like:
Code:
1
6
7
14
15
20
21
96
97
115
.
.
.
1322610
1322620
1322621
1322654
1322655
1322657
1322658
1322661
1322662
1322664

Current O/p:
Code:
h0=1
t0=100008
h1=100009
t1=201120
h1=201121
t1=301524
h1=301525
t1=401938
h1=401939
t1=503160
h1=503161
t1=604185
h1=604186
t1=704649
h1=704650
t1=806089
h1=806090
t1=909204
h1=909205
t1=1009463
h1=1009464
t1=1109665
h1=1109666
t1=1210242
h1=1210243
t1=1311035


Expected O/P:
h0=1
t0=100008
h1=100009
t1=201120
h1=201121
t1=301524
h1=301525
t1=401938
h1=401939
t1=503160
h1=503161
t1=604185
h1=604186
t1=704649
h1=704650
t1=806089
h1=806090
t1=909204
h1=909205
t1=1009463
h1=1009464
t1=1109665
h1=1109666
t1=1210242
h1=1210243
t1=1311035
h1=1311036
t1=1322664

Can someone help

Last edited by Scott; 08-11-2013 at 07:07 PM.. Reason: Returning banned user - Thread closed.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Usage of $ as variable name

Hi I have to use a Environment variable and that variable has $ prefixed to its name like, $var=/home/source/test/ i need to use the variable as i have show above. :confused: Help requested..... Thanks in advance... (6 Replies)
Discussion started by: shreekrishnagd
6 Replies

2. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

3. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

4. UNIX Desktop Questions & Answers

Issue with disk space usage

Issue with disk space usage I have the following line in my "df -h" output: Filesystem Size Used Avail Capacity Mounted on /dev/ad4s1a 496M 495M -39M 109% / What is the issue with having 9% excess utilisation? How can I find out what this partition is... (2 Replies)
Discussion started by: figaro
2 Replies

5. Shell Programming and Scripting

Confused with the usage of one variable usage

Hi All I am not able to understand the usage of d# in the below variable declaration. FILE_LOC contains the directory path And also help me to know about what will be saved in the variable j. Thanks!!! j=${d#${FILE_LOC}/} (2 Replies)
Discussion started by: mohanm
2 Replies

6. Shell Programming and Scripting

Array usage issue with AWk

Hi friends, I m trying to write small script in awk alone. And I have tried below logic for one of my automation - taking the first column of the file in array and will read in for loop for each time when i grep the array value in the same file I should get complete output whichever is matching... (3 Replies)
Discussion started by: Shahul
3 Replies

7. Shell Programming and Scripting

sed usage with Variable

Gurus, I am trying to display a match (single character) from beginning of the line in a file using a variable. I tried using sed ... not sure where am doing it wrong... sed -n "/^\$variable/p" FileName.shor sed -n "/^\${variable}/p" FileName.shBoth of the above are not working.....Thanks... (4 Replies)
Discussion started by: Kevin Tivoli
4 Replies

8. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

9. UNIX for Dummies Questions & Answers

Variable usage

Hi , I am using a simple loop:- for PID in `ps -auxww| grep -v grep | awk '{print $2}'` do echo "Found : $PID : Killing..." kill -9 ${PID} done. I want to know what will be the difference for killing the PID by using :- ${PID} , $PID, `$PID` and '$PID'. I want to... (4 Replies)
Discussion started by: Raj999
4 Replies

10. Shell Programming and Scripting

Usage of # in assignment of variable

guys, i would like to know what does the below does. tr=`echo $bfile | cut -d"." -f4` tr=${tr#TR} i tried with assigning a value and executed second line. but after that also value of tr remains same. thanks in advance .. (1 Reply)
Discussion started by: expert
1 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. Please notice this option isn't related to the terminal length as in a "80 culums terminal". --font=desc Set the font description. Default is Monospace 12. --rtl Do right to left (RTL) layout. --paper ps Choose paper size. Known paper sizes are legal, letter and A4. Default is A4. Postscript points Each postscript point equals to 1/72 of an inch. 36 points are 1/2 of an inch. --bottom-margin=bm Set bottom margin. Default is 36 postscript points. --top-margin=tm Set top margin. Default is 36 postscript points. --left-margin=lm Set left margin. Default is 36 postscript points. --right-margin=rm Set right margin. Default is 36 postscript points. --gutter-width=gw Set gutter width. Default is 40 postscript points. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 01:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy