- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Simple Shell Script problem
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
тАО06-16-2009 03:12 PM
тАО06-16-2009 03:12 PM
Simple Shell Script problem
I need to build a command using the values from each columns. For example:
My file looks like this:
Data1 Data2
Data3 Data4
Data5 Data6
I need to create a command that looks like this:
Dosomething Data1,Data2
My problem is my script simply reads the whol column and attempts to put it all on the command line.
Any help will be appreciated.
Marcus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 03:38 PM
тАО06-16-2009 03:38 PM
Re: Simple Shell Script problem
This is one option:
# cat ./reformat
#!/usr/bin/sh
while read X Y Z
do
echo "somecommand ${X},${Y}"
done < inputfile
# cat ./inputfile
Data1 Data2
Data3 Data4
Data5 Data6
# ./reformat
somecommand Data1,Data2
somecommand Data3,Data4
somecommand Data5,Data6
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 04:04 PM
тАО06-16-2009 04:04 PM
Re: Simple Shell Script problem
Thanks for the quick response! Your solution has got me almost there. I left a small detail out of my original post.
I need two things:
1. The data columns in the file are reversed for the command I am trying to build for example:
I the file the data is arranged as below:
Data1 Data2
Data3 Data4
etc . . .
However my command requires the data be arranged with column 2's data first and then column 1. For example:
somecommand Data2,Data1
somecommand Data4,Data3
somecommand Data6,Data5 etc. . .
Also the final command requires some quotation marks for example: somecommand "Data2","Data1" etc . . .
Thanks!
Marcus.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 04:10 PM
тАО06-16-2009 04:10 PM
Re: Simple Shell Script problem
OK, according to your new requirements, simply do:
# cat ./reformat
#!/usr/bin/sh
while read X Y Z
do
echo "somecommand \"${Y}\",\"${X}\""
done < inputfile
...which produces:
somecommand "Data2","Data1"
somecommand "Data4","Data3"
somecommand "Data6","Data5"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 08:27 PM
тАО06-16-2009 08:27 PM
Re: Simple Shell Script problem
Many Thanks!
Marcus.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2009 09:55 PM
тАО06-16-2009 09:55 PM
Re: Simple Shell Script problem
awk '{print "Dosomething", $1, "," $2}' yourfile