I have a file in which there are strings given below:
inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)
I want to get the nos. only form these.
The o/p should be
1138932
1257904
How to filter this out ??
I have a file in which there are strings given below:
inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)
I want to get the nos. only form these.
The o/p should be
1138932
1257904
How to filter this out ??
You can do by "awk" utility or by "cut" command.
You can also use tr
tr -dc '0123456789' < input.file
Sanjay,
I know what are the filtering tools ..but then i want the solution in terms of syntax based on the query given by me.
Thanks anyways for your suggestion !!
Hey, I know you have used following one..
tr -d
Deletes each character from standard input that is contained in the string specified by String1. Notes:
1 When the -C option is specified with the -d option, all characters except those specified by String1 will be deleted. The contents of String2 are ignored unless the -s option is also specified.
2 When the -c option is specified with the -d option, all values except those specified by String1 will be deleted. The contents of String2 are ignored unless the -s option is also specified.
I have contents in the file...
/clocal/mqbrkrs/user/mqsiadm/sanjay:
inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)
And when I run command given by you then I get following..
47940411389321257904
Don't know from where its been generated ?
Varun,
Try this one !!
cut -d ' ' -f 2 <file_name>|cut -c1-7
I dun't have any Linux/Unix system with me right now, so please check the syntex.
Thanks
Perhaps,
[~]$
echo "inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)" | tr -dc "[:digit:]\n"
1138932
1257904
[~]$
Good try....But then tell me what will you do when the numeric length varies that means it could be of sometimes 7 characters, sometimes more then 7 characters and sometimes less then that. At that time your given option would fail, because immediately the numeric string there is a character attached, presently its 'c'.
inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)
Now tell me !!
Hey,
Thanks buddy, thats what I have been looking for !!
As well I told you that currently I dun have any *NIX box with.
There is one logic in my mind
After the Filter we can use "c" as a delimeter and then cut the firt Filed.
Try It !!
cut -d ' ' -f 2 <file_name>|cut -d 'c' -f 1
Hey,
But what then if even the delimiter is other then c, because i am getting variable input into the file !! Can you place more then 1 delimiters then ??
Anyways as you don't have unix comp. now in front of you, leave it as of now, i got the o/p.
Thanks buddy !!
Hi,
I think think this is ok.
echo inode 1138932c | sed 's/[a-z,A-Z]//g'