- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- while read loop help
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
02-03-2010 02:37 AM
02-03-2010 02:37 AM
while read loop help
any advice will be appreciated
Thanks,
Avinash
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2010 04:19 AM
02-03-2010 04:19 AM
Re: while read loop help
the bets way is to send the loop that you are using.
mikap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 03:49 AM
02-04-2010 03:49 AM
Re: while read loop help
What OS and shell are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 06:38 AM
02-04-2010 06:38 AM
Re: while read loop help
I would urge you to *post* your code. I suspect that you need two file descriptors --- one for the 'read' loop and another for the process you want to execute. If an 'ssh' or 'remsh' is called within the loop you will likely need to add the '-n' option to it.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 06:57 AM
02-04-2010 06:57 AM
Re: while read loop help
Wrong:
#!/bin/sh
# this reads only the first line
while read foo < inputfile.txt
do
echo "$foo"
done
Right:
#!/bin/sh
# this processes all lines in the file
while read foo
do
echo "$foo"
done < inputfile.txt
The "for i in $(cat inputfile.txt)" style loop is not suitable for files longer than the maximum command line length (8 KiB or so). If the file is longer than that, the script dies with "Command line too long" or equivalent error message.
With smaller files, it might work... but not the same as the "while read" loop: $i will iterate over the content of the input file, but one _word_ at a time, not one _line_ at a time.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 04:43 PM
02-04-2010 04:43 PM
Re: while read loop help
cat file | while read a (* or, number of words per line, a b c d e *)
do
echo $a (* whole line *)
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2010 08:23 PM
02-04-2010 08:23 PM
Re: while read loop help
Please post the code which would help.
Sagar