- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- read complete lines in a for loop
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-10-2002 05:53 AM
06-10-2002 05:53 AM
Can anyone help me out here, I need to read completes Lines of a File in a for loop.
for i in //filename//
and i is supposed to be the first, second etc. line of that file.
Anyone got an Idea how I could do that ?
kind regards
Oliver
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 05:54 AM
06-10-2002 05:54 AM
Re: read complete lines in a for loop
do
echo $i
done
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 06:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 06:04 AM
06-10-2002 06:04 AM
Re: read complete lines in a for loop
You must beware with the spaces or tabs character into the file, this is because the for structure takes this as a separator.
If you have spaces in your file you must replace (use sed) by a different character in order to use the whole line as one parameter.
Hope this helps,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 06:08 AM
06-10-2002 06:08 AM
Re: read complete lines in a for loop
IFS=:
exec 0while read -r Name Pass Uid Gid Comm Home Shell
do
print "$Name $Uid $Gid"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 06:33 AM
06-10-2002 06:33 AM
Re: read complete lines in a for loop
Please try this..I have tested now
for i in "`cat file`"
do
echo "$i"
done
Best of luck
Shahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 07:39 AM
06-10-2002 07:39 AM
Re: read complete lines in a for loop
Here's another method (takes care of spaces and tabs):
#!/usr/bin/sh
inc=1
total=`cat $1 | wc -l`
while [ "$inc" -le "$total" ]
do
tail -$inc $1 | head -1
inc=`expr $inc + 1`
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 07:49 AM
06-10-2002 07:49 AM
Re: read complete lines in a for loop
Sorry, made a typo (swapped the head and tail). Should be:
#!/usr/bin/sh
inc=1
total=`cat $1 | wc -l`
while [ "$inc" -le "$total" ]
do
head -$inc $1 | tail -1
inc=`expr $inc + 1`
done
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 07:54 AM
06-10-2002 07:54 AM
Re: read complete lines in a for loop
INFILE="myfilename"
exec 9<${INFILE}
X=$(line <&9)
STAT=$?
while [ ${STAT} -eq 0 ]
do
echo "${X}"
X=$(line <&9)
STAT=$?
done
Reading using a file descriptor reads the lines sequentially.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2002 08:22 AM
06-10-2002 08:22 AM
Re: read complete lines in a for loop
# perl -pe 1 file
Read file by line and insert line number at front
# perl -pe 's/^/$. /' file
Read file by line and make it useful (if the content is possitive)
# perl -pe 's/ms-?dos/hp-ux/ig' file