- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script question: update fields in a txt file
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
03-31-2006 06:24 AM
03-31-2006 06:24 AM
script question: update fields in a txt file
I am going to scan a txt file every 5 minutes, and will update the column(s) in the file depends on the current situation.
For example: itemprice.txt
CPU 110
Memory 80
Vediocard 50
...
I need to update the numbers every time I scan this file.
How can I script this?
Thanks a lot!
while read -r col1 col2
do
# read the price from database
# want to update $col2, and write to the file, but how to do here?
done < itemprice.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2006 06:27 AM
03-31-2006 06:27 AM
Re: script question: update fields in a txt file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2006 06:33 AM
03-31-2006 06:33 AM
Re: script question: update fields in a txt file
typeset TDIR=${TMPDIR:-/var/tmp}
typeset T1=${TDIR}/X${$}_1.tmp
typeset INFILE=itemprice.txt
typeset col1=""
typeset col2=""
typeset NEWCOL2="xxx"
while read -r col1 col2
do
# do whatever to set ${NEWCOL2}
echo "${col1} ${NEWCOL2}" >> ${T1}
done < ${INFILE}
mv ${T1} ${INFILE}
There are much more efficient ways to do this using perl, awk, or sed but you seemed to want a shell approach.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2006 06:50 AM
03-31-2006 06:50 AM
Re: script question: update fields in a txt file
exec >yourtextfile
for x `cat listofthings` ; do
newprice=`lookupdb $x`
echo $x $newprice
done
Where-
- yourtextfile is where to put the results
- listofthings is just the col 1 items
- lookupdb is the program to look up price
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2006 06:59 AM
03-31-2006 06:59 AM
Re: script question: update fields in a txt file
It all depends on how you're reading the item prices from the database and how you're storing them? Whether you are using shell or database variables for storing the item prices read from the database? It will help if you could be specific.
thanks!