- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- [Q] simple shell command question ..
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
06-01-2006 12:47 AM
06-01-2006 12:47 AM
[Q] simple shell command question ..
$ cat test.txt
m12345678
m76543210
m09876543
m98765432
...
I would like to split this 9 digit to 8 digit.
(want to remove last character such as
m1234567
m7654321
...
Would you recommand any command to do this ?
like awk, sed etc ...
I am not sure what option is available to this at awk.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 12:49 AM
06-01-2006 12:49 AM
Re: [Q] simple shell command question ..
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 12:53 AM
06-01-2006 12:53 AM
Re: [Q] simple shell command question ..
TMTOWTDI (There's More Than One Way To Do It). Here's one using shell commands and 'cut':
while read LINE
do
echo ${LINE}|cut -c1-8
done < filein > fileout
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 12:53 AM
06-01-2006 12:53 AM
Re: [Q] simple shell command question ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 12:57 AM
06-01-2006 12:57 AM
Re: [Q] simple shell command question ..
For fun, and brevity, you could do:
# perl -pli.old -e 'chop' file
This reads and chops the last character of every line (which is what you wanted); makes a backup copy of your input file as "file.old" and replaces "file" with the modified copy.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 01:55 AM
06-01-2006 01:55 AM
Re: [Q] simple shell command question ..
don't know what your statement about 'm' means - I guess only strings starting with 'm' and length 9 should be modified.
awk '$1 ~ /^m/ && length($1)==9 {print substr($1,1,8);next}
{print}' test.txt
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 03:45 AM
06-01-2006 03:45 AM
Re: [Q] simple shell command question ..
# sed '/^m/s/\(.*\).$/\1/g' test.txt
OR with awk as...
# awk '{sub(/.$/,"");print $0}' test.txt
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 04:04 AM
06-01-2006 04:04 AM
Re: [Q] simple shell command question ..
sed way...
# sed -n '/^m.\{8\}$/ s/\(.*\).$/\1/p' test.txt
awk way...
# awk '$0~/^m/ && length($0)==9 {sub(/.$/,"");print $0}' test.txt
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 04:28 AM
06-01-2006 04:28 AM
Re: [Q] simple shell command question ..
sed version...
# sed -n '/^m[0-9]\{8\}$/ s/\(.*\).$/\1/p' test.txt
awk version...
# awk '$0~/^m[0-9]{8}$/ {sub(/.$/,"");print $0}' test.txt
hope it helps!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2006 02:36 PM
06-01-2006 02:36 PM
Re: [Q] simple shell command question ..
while read var restOfLine
do
print "${var%?}"
done < yourFile