- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script need 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
Discussions
Discussions
Forums
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
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-18-2011 07:47 PM
тАО01-18-2011 07:47 PM
script need help
I am writing some script to construct a new variable called CG_GRP
for CG in `/bin/cat /opt/bin/mylist.txt`
do
echo "$CG"
CG_GRP=$CG
done
But the result will return the item line by line instead of one line.
For Example in mylist.txt I have the following:
Apple
Orange
I want the output to be in single line and separate by just one blank space.
Apple Orange
Instead of
Apple
Orange
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2011 09:45 PM
тАО01-18-2011 09:45 PM
Re: script need help
What kind of (shell) script? "#!/???/??"?
On what?
uname -a
As usual, many things are possible, and "cat"
may not be needed.
dyi # cat mylist.txt
Apple
Orange
dyi # cat mylist.sh
#!/bin/sh
cg_grp=''
while read line ; do
cg_grp="${cg_grp} ${line}"
done
echo ">${cg_grp}<"
dyi # ./mylist.sh < mylist.txt
> Apple Orange<
dyi #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2011 12:07 AM
тАО01-19-2011 12:07 AM
Re: script need help
# This embeds a newline in the variable:
CG_GRP=$(< /opt/bin/mylist.txt)
echo quoted: "$CG_GRP"
echo not quoted: $CG_GRP
# This uses echo to replace newlines by space:
CG_GRP=$(echo $(< /opt/bin/mylist.txt))
echo quoted: "$CG_GRP"
echo not quoted: $CG_GRP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2011 12:35 AM
тАО01-19-2011 12:35 AM
Re: script need help
When you do an echo of a variable the behavior could vary depend of you set the variable among double quotes, when this hapen the output will be a list, in your case:
Apple
Orange
Try the variable echo without double quotes.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2011 06:29 AM
тАО01-19-2011 06:29 AM
Re: script need help
for CG in `/bin/cat /opt/bin/mylist.txt`
do
echo $CG "\c"
CG_GRP=$CG
done
I think you could put quotes around $CG and it would come out the same.
Just a thought,
Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2011 07:01 AM
тАО01-19-2011 07:01 AM
Re: script need help
TMTOWTDI :
# cat ./showme
#!/usr/bin/sh
while read LINE
do
echo "$LINE \c"
done < /opt/bin/mylist.txt
echo
exit 0
...Note that we let the shell perform the read and eliminate the use of the extra process (and I/O) when the 'cat' was used.
Regards!
...JRF...