- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script help
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-27-2005 04:20 AM
06-27-2005 04:20 AM
i am writing a shell script, where i have got some doubts, can somebody clear me..
my file name is arpt_356789.dbf
which is saved in variable reala
now, i want to cut the number alone 356789,
if i use the cut -c 6-11 i will get the number, but in future the filenumbers may increase the counter value.. can anybody help me in getting that number alone from the variable.. ( i feel some ascii conversion loop is required .. i dont know.. just a guess)
can somebody help me..
also,
how to sftp to other server automatically without typing the password ??
my server is using HPUX 11.11
thanks in advance,
sivakumar p.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 04:27 AM
06-27-2005 04:27 AM
SolutionShell patern atching would fasted and it will be shell built in function.
Is pattern arpt_xxxx.dbf common, if yes do it as follows
var1=arpt_356789.dbf
echo ${var1#arpt_}|awk -F . '{print $1}'
With awk
cat "arpt_356789.dbf" |awk -F _ '{print $2}'|awk -F . '{print $1}'
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 05:07 AM
06-27-2005 05:07 AM
Re: shell script help
$ echo $file
arpt_356789.dbf
$ echo $file|tr -cd \[0-9]
356789
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 05:09 AM
06-27-2005 05:09 AM
Re: shell script help
echo ${file#*_}|cut -d. -f1
356789
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 05:14 AM
06-27-2005 05:14 AM
Re: shell script help
But I'd say the most lightweight is
shell variable expansion or usage of shell built-ins (read man sh-posix)
Then comes tr.
The mos heavy weight are interpreters like awk or Perl.
And if you use the latter two,
don't spend superfluous program calls like cat (awk like grep does this inherently)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 06:33 AM
06-27-2005 06:33 AM
Re: shell script help
inspired by Ralph:
# var1=arpt_356789.dbf
# newvar=$(echo $var1| tr -cd '[^0-9]')
# echo $newvar
356789
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 06:57 AM
06-27-2005 06:57 AM
Re: shell script help
sh-3.00$ var1=arp1t_356789.dbf
sh-3.00$ newvar=$(echo $var1| tr -cd '[^0-9]')
sh-3.00$ echo $newvar
1356789
sh-3.00$ var1=arpt_356789.dbf1
sh-3.00$ newvar=$(echo $var1| tr -cd '[^0-9]')
sh-3.00$ echo $newvar
3567891
sh-3.00$
If you know it's the only number in the name, you're safe. If there might be more, you're not
if you want the first number
sh-3.00$ var1=arpt_356789.dbf1
sh-3.00$ newvar=$(echo $var1 | perl -ne'/(\d+)/&&print$1')
sh-3.00$ echo $newvar
356789
sh-3.00$
sed will do too I guess
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 07:01 AM
06-27-2005 07:01 AM
Re: shell script help
Your filename is stored in a shell script variable and to extract the number string from it, follow the awk excerpt given below:
=============================================
FNAME=arpt_356789.dbf
echo $FNAME | awk -F"." '{print z[split($1,z,"_")]}'
=============================================
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 07:23 AM
06-27-2005 07:23 AM
Re: shell script help
for the above take a look at this URL
http://www.snailbook.com/faq/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2005 10:53 PM
06-27-2005 10:53 PM
Re: shell script help
procura, that perl syntax doesn't worked.
anyway, i am using anils solution.
it worked fine.
thanks everybody once again
sivakumar p.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2005 12:59 AM
06-28-2005 12:59 AM
Re: shell script help
# echo "arpt_356789.dbf" | sed 's/^.*_//;s/\..*$//'
356789
# echo "arpt_356789.dbf" | perl -pe 's/^.*_//;s/\..*$//'
356789
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2005 01:33 AM
06-28-2005 01:33 AM
Re: shell script help
$ echo arpt_356789.dbf | cut -f2 -d"_" | cut -f1 -d"."
356789
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2005 02:43 AM
06-28-2005 02:43 AM
Re: shell script help
it worked.
sivakumar p.