The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to filter out some paragraphs in a file cnlhap Shell Programming and Scripting 7 08-19-2008 04:03 PM
File filter Dastard Shell Programming and Scripting 3 09-06-2007 02:50 PM
how do I filter double lines from a txt file I-1 Shell Programming and Scripting 10 02-20-2007 01:21 PM
filter parts of a big file using awk or sed script apalex Shell Programming and Scripting 1 07-25-2005 05:45 PM
filter out certain column from a file CamTu Shell Programming and Scripting 4 04-04-2005 07:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-17-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Exclamation filter the string from a file ??

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 ??
  #2 (permalink)  
Old 09-17-2007
SanjayLinux SanjayLinux is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 58
You can do by "awk" utility or by "cut" command.
  #3 (permalink)  
Old 09-17-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
You can also use tr

Code:
tr -dc '0123456789' < input.file
  #4 (permalink)  
Old 09-17-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by vino View Post
You can also use tr

Code:
tr -dc '0123456789' < input.file
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 ?
  #5 (permalink)  
Old 09-17-2007
SanjayLinux SanjayLinux is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 58
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
  #6 (permalink)  
Old 09-17-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Perhaps,
Code:
[~]$ 
echo "inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)" | tr -dc "[:digit:]\n"
1138932
1257904
[~]$
  #7 (permalink)  
Old 09-17-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Lightbulb

Quote:
Originally Posted by SanjayLinux View Post
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
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 !!
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0