- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting question: retaining spaces when loo...
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
10-07-2003 04:49 AM
10-07-2003 04:49 AM
Input file contains:
GA30494 0000 Y john_j_read@aul.com
GA620870220022 Y john_j_read@aul.com
My loop:
cat extfile |while read line
do
CONTRACT=`echo $line |cut -c 1-20`
ACT=`echo $line |cut -c 21`
SENDTO=`echo $line |cut -c 22-82`
echo "${CONTRACT}" "${ACT}" "${SENDTO}"
done
GA30494 0000 Y john_ j _read@aul.com
GA620870220022 Y joh n _j_read@aul.com
Notice that "cat" and cut are not the problem:
#cat extfile |cut -c 1-20
GA30494 0000
GA620870220022
#cat extfile |cut -c 21
Y
Y
#cat extfile |cut -c 22-82
john_j_read@aul.com
john_j_read@aul.com
Thanks! I'm willing to entertain other language options such as Perl!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 04:54 AM
10-07-2003 04:54 AM
Solutionprintf "%s20 %1s %60s\n",$CONTRACT,$ACT,$SENDTO
Should do the trick.
--Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 04:59 AM
10-07-2003 04:59 AM
Re: Scripting question: retaining spaces when looping read/echo statements
In the above post, the input file should look like:
Field 1 is colums 1-20
Field 2 is column 21
Field 3 is colums 22-82
GA30494 0000 Y john_j_read@aul.com
GA620870220022 Y john_j_read@aul.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 05:06 AM
10-07-2003 05:06 AM
Re: Scripting question: retaining spaces when looping read/echo statements
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 05:16 AM
10-07-2003 05:16 AM
Re: Scripting question: retaining spaces when looping read/echo statements
I'll give you both 10's!
Looks like putting quotes around $line is the easiest answer for me!
It worked! Thanks very much!!!
cat extfile |while read line
do
CONTRACT=`echo "$line" |cut -c 1-20`
ACT=`echo "$line" |cut -c 21`
SENDTO=`echo "$line" |cut -c 22-82`
echo "${CONTRACT}" "${ACT}" "${SENDTO}"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2003 06:03 AM
10-07-2003 06:03 AM
Re: Scripting question: retaining spaces when looping read/echo statements
typeset -L20 CONTRACT
typeset -L60 SENDTO
That would left justify and pad on the right w/ whitespace out to 20 or 60 respectively. There is also the R equivalent as well.