HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Look at flat file base on the CTL with cut
Operating System - HP-UX
1833779
Members
2079
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
05-18-2004 03:58 AM
05-18-2004 03:58 AM
Hello,
I need to extract specific column of a file.
The column are defined position-wise in a control file.
I don't want to do any calculation on the position to get the length of a field in order to use substr awk function.
I'm looking for a way to do something like :
cut -c1-5 -c16-23 -c6-15 -c163-171 $FILE
The thing is cut only accept one filed extraction at a time.
Can someone provide a mean to do this ?
Thanks
Nicolas
I need to extract specific column of a file.
The column are defined position-wise in a control file.
I don't want to do any calculation on the position to get the length of a field in order to use substr awk function.
I'm looking for a way to do something like :
cut -c1-5 -c16-23 -c6-15 -c163-171 $FILE
The thing is cut only accept one filed extraction at a time.
Can someone provide a mean to do this ?
Thanks
Nicolas
All different, all Unix
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2004 04:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2004 04:19 AM
05-18-2004 04:19 AM
Re: Look at flat file base on the CTL with cut
A RTFM case
Silly me ...
Silly me ...
All different, all Unix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2004 04:43 AM
05-18-2004 04:43 AM
Re: Look at flat file base on the CTL with cut
Well there is one potential problem with the list to feed cut, all the components will be bunched together in one output field. If you want to separate into four distinct fields then you need to do something a little different.
cut -c1-5,16-23,6-15,163-171 $FILE
The above command will produce one output field and unless there are built-in spaces in your input line, it may not be useful.
Now let's suppose that you actually want 4 distinct variables loaded:
#!/usr/bin/sh
cut_em()
{
typeset S="${1}"
shift
while [[ ${#} -ge 1 ]]
do
echo "${S}" | cut "${1}" | tr -d "\n"
if [[ ${#} -gt 1 ]]
then
echo " \c"
fi
shift
done
echo
return 0
} # cut_em
cat ${FILE} | while read X
do
cut_em "${X}" -c1-5 -c16-23 -c6-15 -c163-171 | read A B C D
echo "A: ${A} B: ${B} C: ${C} D: ${D}"
done
Note that the cut_em function uses the same argument convention as your initial approach but now we have 4 distinct variables loaded.
It would be faster to do all this in awk and let it parse your argument list but you wanted cut.
cut -c1-5,16-23,6-15,163-171 $FILE
The above command will produce one output field and unless there are built-in spaces in your input line, it may not be useful.
Now let's suppose that you actually want 4 distinct variables loaded:
#!/usr/bin/sh
cut_em()
{
typeset S="${1}"
shift
while [[ ${#} -ge 1 ]]
do
echo "${S}" | cut "${1}" | tr -d "\n"
if [[ ${#} -gt 1 ]]
then
echo " \c"
fi
shift
done
echo
return 0
} # cut_em
cat ${FILE} | while read X
do
cut_em "${X}" -c1-5 -c16-23 -c6-15 -c163-171 | read A B C D
echo "A: ${A} B: ${B} C: ${C} D: ${D}"
done
Note that the cut_em function uses the same argument convention as your initial approach but now we have 4 distinct variables loaded.
It would be faster to do all this in awk and let it parse your argument list but you wanted cut.
If it ain't broke, I can fix that.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP