- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- posix shell script array
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 11:42 PM
06-04-2003 11:42 PM
posix shell script array
if I have text file as below
---------------textfile.txt-----------------
messages line 1
messages line 2
messages line 3
messages line 4
messages line 5
messages line 6
messages line 7
messages line 8
messages line 9
messages line 10
------------------------------------------------
I want to cut every 5 lines and send to filter
and then go to next 5 lines and send to filter again until end of file with out using temp file
(because I want to tuning performance , my old script using temp file and sed command to cut line 1 to 5
from temp file and send to filter)
I got input from program just like command as below
cat textfile.txt|tee
I want to use output from this command just like
cat textfile.txt|tee
program ....
...
...
How can I write shell script to handle this process
I can not use "while read -r xx" command because this command get input from text file but I want to insert this
code to my program.
Can I use array ?
Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2003 01:29 AM
06-05-2003 01:29 AM
Re: posix shell script array
I don't really understand what you need. Could you please be more explicit on your input and output and how you want to use it or perhaps even post your old script ?
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2003 01:39 AM
06-05-2003 01:39 AM
Re: posix shell script array
Rgds Jarle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2003 01:42 AM
06-05-2003 01:42 AM
Re: posix shell script array
--------
.
.
.
/usr/bin/tee | sed 's/^C//' | pr -t -l${_length} > $file
reset_printer
cat /usr/lib/asx/thai/pre15cpi.fnt
cat /usr/lib/asx/thai/thaib410n.fnt
echo "^[(1X\c"
esc1="^[\&\l5C"
esc2="^[\&\l48D"
FileLen=`cat $file|wc -l`
nLoop=`expr $FileLen / $_length`
LastLen=`expr $FileLen % $_length`
LoopCount=1
ARG="-pr=/usr/lib/asx/thai/prn/dumb -i=/usr/lib/asx/thai/code/sic-tis -o=/usr/lib/asx/thai/code/tis-sic -rm400 -cb2 -lpg44"
while [ ${LoopCount} -le ${nLoop} ]
do
cat $PCL_FILE # Print Pre-Printed Form
case ${_job_name} in
CSA*) echo "^[&a3R^[&a1C\c"
echo "\033&a5L\c" # set left margin
;;
esac
StartLine=`expr \( $LoopCount - 1 \) \* $_length + 1`
EndLine=`expr $LoopCount \* $_length`
sed -n "$StartLine,$EndLine p" $file |
/usr/lbin/thfil $ARG|sed 'G
s/\n/'$esc1'/
n
n
G
s/\n/'$esc2'/'
LoopCount=`expr $LoopCount + 1`
done
if [ $LastLen -gt 0 ]
then
cat $PCL_FILE # Print Pre-Printed Form
case ${_job_name} in
CSA*) echo "^[&a3R^[&a1C\c"
echo "\033&a5L\c" # set left margin
;;
esac
StartLine=`expr $nLoop \* $_length + 1`
EndLine=`expr $FileLen`
sed -n "$StartLine,$EndLine p" $file |
/usr/lbin/thfil $ARG|sed 'G
s/\n/'$esc1'/
n
n
G
s/\n/'$esc2'/'
fi
font_reset
rm -f $file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2003 01:57 AM
06-05-2003 01:57 AM
Re: posix shell script array
If I read this correctly, and without using perl, you maybe want something like:
while :;do
i=0
while [ $i -ne 5 ]; do
read line || break
a[$i]=$line
let i=i+1
done
echo ${a[*]}
sleep 1
test "$line" || exit
unset a
i=0
done
then you'd run it by typing:
cat textfile.txt | scriptname
the script sleeps for one sec. after reading 5 lines, that's where you could put your filter.
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2003 02:38 AM
06-05-2003 02:38 AM
Re: posix shell script array
I'm not sure that it would really be an enhancement but you can also use read with -p option.
just add "|&" at the end of first sed and use read -p to get input later in the script :
/usr/bin/tee | sed 's/^C//' | pr -t -l${_length} |&
...
while read -p xxx
A simplier example of this usage would be :
#!/usr/bin/sh
ll |&
while read -p file
do
echo "***$file***"
done
You will see that each line of ll input will be read as needed.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2003 12:54 AM
06-10-2003 12:54 AM