filter the string from a file ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filter the string from a file ??
# 1  
Old 09-17-2007
Error 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  
Old 09-17-2007
You can do by "awk" utility or by "cut" command.
# 3  
Old 09-17-2007
You can also use tr

Code:
tr -dc '0123456789' < input.file

# 4  
Old 09-17-2007
Quote:
Originally Posted by SanjayLinux
You can do by "awk" utility or by "cut" command.
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 !!
Smilie
# 5  
Old 09-17-2007
Quote:
Originally Posted by vino
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 ?
Smilie
# 6  
Old 09-17-2007
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
# 7  
Old 09-17-2007
Perhaps,
Code:
[~]$ 
echo "inode 1138932c(mqsiadm)
inode 1257904c(mqsiadm)" | tr -dc "[:digit:]\n"
1138932
1257904
[~]$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to filter string between specific string in ksh

My argument has data as below. 10.9.9.85 -rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr5.scr 127869538 -rwxr-xr-x user1 2019-10-15 17:40 /app/scripts/testingscr56scr 127869538 ....... (note all these between lines will start with hyphen '-' ) -rwxr-xr-x user1 2019-10-15 17:40... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

3. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

4. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

5. Shell Programming and Scripting

Perl script to filter the string

Hi folks, I have a log file with the lines in the below format. Jul 1 23:00:51 10.212.3.251 SS: %SYS-7-CLI_SCHEDULE: some error occured I want to split the line based on the " %SYS-7-CLI_SCHEDULE: " value. The criteria is the should store the word that starts with % i.e., ... (1 Reply)
Discussion started by: scriptscript
1 Replies

6. UNIX for Dummies Questions & Answers

Help me to filter a file

I want to view a file ignoring mutilple comment line (/*....*/). Please help me on this. Advance thanks.:b: (5 Replies)
Discussion started by: Pradipta Kumar
5 Replies

7. UNIX for Dummies Questions & Answers

Filter a particular string

Hi, I have a long log file. Out of which I want to filter particular occurrences where APC=4-033-0. Please help how it can be done. Input : +++ ELEMENT 12-05-27 23:15:06 CC 3482 #040185 > REPT APB TPE=C7NTL SM=22 OPC=4-003-7 APC=4-033-4 inaccessible END OF REPORT #040185 ++- ... (7 Replies)
Discussion started by: vanand420
7 Replies

8. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

9. Shell Programming and Scripting

Sed filter words from string

I have following string in a variable: str="sstring garbage adfsdf tab.col1 lkad rjfj tab2.col2 adja tab2.col4 garbage" I want to filter "word.word" pattern from it. I assume the pattern won't occur in start or end of the string. Output shoud be: tab.col1 tab2.col2 tab2.col4 Can this be... (7 Replies)
Discussion started by: amicon007
7 Replies

10. Shell Programming and Scripting

File filter

Hi Everyone , have a nice i would need a little help on this i have file which contains blocks such as given below <hgsdp:msisdn=923228719047,loc; HLR SUBSCRIBER DATA SUBSCRIBER IDENTITY MSISDN IMSI STATE AUTHD 923228719047 410072110070614 CONNECTED ... (3 Replies)
Discussion started by: Dastard
3 Replies
Login or Register to Ask a Question