- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Simple scripting question
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
01-15-2003 12:03 PM
01-15-2003 12:03 PM
I have a "for" loop which cats a file. The file contains 2 columns of data separated by a space. I want each line to come into the loop as 1 argument instead of two. No matter how I've tried to quote things it keeps treating each word in the document as 1 pass through the loop.
for i in `cat /tmp/rfile`
do
echo $i
done
assuming /tmp/rfile contains:
abc 123
def 456
etc...
The output looks like
abc
123
def
456
I want it to look like
abc 123
def 456
I want the value of $i to be "abc 123" first time, and "def 456" second time.
Thanks in advance!
Tim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 11:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 11:44 AM
01-15-2003 11:44 AM
Re: Simple scripting question
Add this to your cat:
cat /tmp/rfile|sed "s/ //g"
or if they are possibly tabs and/or spaces:
cat /tmp/rfile|sed "s/[[:space:]]//g"
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 11:45 AM
01-15-2003 11:45 AM
Re: Simple scripting question
#!/usr/bin/sh
cat /tmp/rfile | while read i
do
echo "${i}"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 11:51 AM
01-15-2003 11:51 AM
Re: Simple scripting question
exec 3< /tmp/rfile
i=`line <& 3`
while test "$?" -eq 0
do
echo $i
i=`line <& 3`
done
those are back-tiks rather than single quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 12:09 PM
01-15-2003 12:09 PM
Re: Simple scripting question
My file looked like this:
# cat test
abc 123
def 456
ghi 789
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 12:09 PM
01-15-2003 12:09 PM
Re: Simple scripting question
This will yield what you seek:
while read F1 F2
do
echo $F1 $F2
done < /tmp/rfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 12:10 PM
01-15-2003 12:10 PM
Re: Simple scripting question
Try this small program:
while read LINE
do
echo $LINE
done
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 12:14 PM
01-15-2003 12:14 PM
Re: Simple scripting question
IFS=""
while read LINE
do
echo $LINE
done
Setting IFS to null will prevent "read" from breaking up the input line into "words".
HTH
-- Rod Hills