- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Print sequence and prefix
Operating System - HP-UX
1752290
Members
5112
Online
108786
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
Discussions
Discussions
Forums
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
тАО06-01-2009 03:32 AM
тАО06-01-2009 03:32 AM
Print sequence and prefix
Hi All,
I have a file "MATSX_M_2009042800009352.dat", i just need to print sequence from the file i.e before dot 4 digits and need to print file prefix as "MATSX_M" first 7 characters of file.
Please help me in this issue as iam new to unix.
I have a file "MATSX_M_2009042800009352.dat", i just need to print sequence from the file i.e before dot 4 digits and need to print file prefix as "MATSX_M" first 7 characters of file.
Please help me in this issue as iam new to unix.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2009 03:39 AM
тАО06-01-2009 03:39 AM
Re: Print sequence and prefix
Hi:
Do you mean this?
# X="MATSX_M_2009042800009352.dat"
# echo ${X}|awk '{print substr($0,1,7)substr($0,21,4)}'
MATSX_M9352
Regards!
...JRF...
Do you mean this?
# X="MATSX_M_2009042800009352.dat"
# echo ${X}|awk '{print substr($0,1,7)substr($0,21,4)}'
MATSX_M9352
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2009 03:43 AM
тАО06-01-2009 03:43 AM
Re: Print sequence and prefix
Hi JRF,
Thanks for your support.
Thanks for your support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-01-2009 03:51 AM
тАО06-01-2009 03:51 AM
Re: Print sequence and prefix
You want to pick some components of the file name, right?
Too bad you did not specify exactly how you wish the output formatted...
I assume the length of the filename is fixed? If it isn't, there is a different way for pickign the sequence number, but it is not as clear as using the "cut" command.
A short script can do the job:
#!/bin/sh
for FILENAME in "$@"
do
PREFIX=$( echo "$FILENAME" | cut -c 1-7 )
SEQUENCE=$( echo "$FILENAME" | cut -c 21-24 )
echo "prefix: $PREFIX sequence: $SEQUENCE"
done
Save this script as a text file and give it execute permissions (chmod a+x <scriptname>).
Then you can use it like:
./<scriptname> *.dat
This script can handle an unlimited number of filenames: the effective limit is the maximum length of the command line. Wildcards are not a problem either (as they are a feature of the shell, not of the script).
The script will produce one line of output for each name listed on the command line.
If you want to change the format of the output line, simply edit the "echo" line of the script.
MK
Too bad you did not specify exactly how you wish the output formatted...
I assume the length of the filename is fixed? If it isn't, there is a different way for pickign the sequence number, but it is not as clear as using the "cut" command.
A short script can do the job:
#!/bin/sh
for FILENAME in "$@"
do
PREFIX=$( echo "$FILENAME" | cut -c 1-7 )
SEQUENCE=$( echo "$FILENAME" | cut -c 21-24 )
echo "prefix: $PREFIX sequence: $SEQUENCE"
done
Save this script as a text file and give it execute permissions (chmod a+x <scriptname>).
Then you can use it like:
./<scriptname> *.dat
This script can handle an unlimited number of filenames: the effective limit is the maximum length of the command line. Wildcards are not a problem either (as they are a feature of the shell, not of the script).
The script will produce one line of output for each name listed on the command line.
If you want to change the format of the output line, simply edit the "echo" line of the script.
MK
MK
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP