Shell Scripting | Return list of unique characters in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting | Return list of unique characters in files
# 8  
Old 11-28-2016
Thanks Chubler! This expands my horizon and is easy to use. Any idea on how not having to have to input 10, 11 & 20 at all? Perhaps a range from 00 to 99? So that whatever number is at position 521-522 is returned?

---------- Post updated at 08:44 PM ---------- Previous update was at 08:35 PM ----------

Thanks Aia, you are correct, the ABC was included in the 134 or 521, I do not explain myself very well.

Last edited by clippertm; 11-28-2016 at 09:54 PM..
# 9  
Old 11-28-2016
Sorry I misinterpreted your requirements and believed you had a number of values in the range of 00 thru 99 and not all the values.

to match any two digit number I would use:

Code:
strings *.* | grep "ABCD" | cut -c 521-522 | egrep '[0-9][0-9]' | sort | uniq

This User Gave Thanks to Chubler_XL For This Post:
# 10  
Old 11-29-2016
Quote:
Originally Posted by Chubler_XL
Sorry I misinterpreted your requirements and believed you had a number of values in the range of 00 thru 99 and not all the values.

to match any two digit number I would use:

Code:
strings *.* | grep "ABCD" | cut -c 521-522 | egrep '[0-9][0-9]' | sort | uniq

You might speed that up a little bit with:
Code:
strings *.* | awk '/ABCD/ && (s = substr($0, 521, 2)) ~ /[0-9][0-9]/ {print s}' | sort -u

But note that if you use strings on a text file, the output from strings might not be complete lines from your input files. Have you really checked the output from strings *.* is producing output with the two digits you want in positions 521 and 522?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies

2. Shell Programming and Scripting

Find a string and then return the next 20 characters in multiple files

Hello all, I have a directory with 2000+ files. I need to look in each file for an invoice number. To identify this, i can search for the string 'BIG' and then retrieve the next 30 characters. I was thinking awk for this, but not sure how to do it. Each file contains one long string and in... (8 Replies)
Discussion started by: jdinero
8 Replies

3. Shell Programming and Scripting

compare 2 files and return unique lines in each file (based on condition)

hi my problem is little complicated one. i have 2 files which appear like this file 1 abbsss:aa:22:34:as akl abc 1234 mkilll:as:ss:23:qs asc abc 0987 mlopii:cd:wq:24:as asd abc 7866 file2 lkoaa:as:24:32:sa alk abc 3245 lkmo:as:34:43:qs qsa abc 0987 kloia:ds:45:56:sa acq abc 7805 i... (5 Replies)
Discussion started by: anurupa777
5 Replies

4. Shell Programming and Scripting

Shell Scripting Function call return value

Hi I have a function : Make_Report() { trx_report=`sqlplus -s $conn_str << @@ set echo off; set pages 0; set feedback off; set verify off; select srv_trx_s_no,... (1 Reply)
Discussion started by: neeraj617
1 Replies

5. Shell Programming and Scripting

Return error if - or certain characters are present in a list of strings

I have a list of strings, for example: set strLst = "file1 file2 file3 file4" I want to log an error if some of the fields happen to begin with -, or have characters like ; : ' , ? ] { = Which means for example setting set ierr = 1 (2 Replies)
Discussion started by: kristinu
2 Replies

6. UNIX for Dummies Questions & Answers

remove characters from list of files

done some homework on this-- after i remove up to and including the ) i want to take newfile.txt and use that list to remove the files from a file in my the directory pwd i have a input.txt file cat input,txt 1)mary.jpg 12)john.jpg 100)frankkfkdf .jpg i want to remove the characters in the... (1 Reply)
Discussion started by: plener
1 Replies

7. Shell Programming and Scripting

Help to find string and return following characters from list of files

Hi, I'm fairly new to UNIX, but hopefully some-one can help me with this: I am using the following code to find files with the name "example.xml": find . -name "example.xml" -print that would print me a list like the example here: ./dir1/dir2/example.xml... (5 Replies)
Discussion started by: boijie
5 Replies

8. Shell Programming and Scripting

return a list of unique values of a column from csv format file

Hi all, I have a huge csv file with the following format of data, Num SNPs, 549997 Total SNPs,555352 Num Samples, 157 SNP, SampleID, Allele1, Allele2 A001,AB1,A,A A002,AB1,A,A A003,AB1,A,A ... ... ... I would like to write out a list of unique SNP (column 1). Could you... (3 Replies)
Discussion started by: phoeberunner
3 Replies

9. Shell Programming and Scripting

How to capture return value from java in shell scripting

Hi All, My shell script will call a java component with some arguments , the java component returns a string value to the shell script. How to assign the return value to the shell variable. Here is the sample code. In my shell script i am calling the java as fallows. --exporting... (1 Reply)
Discussion started by: rajeshorpu
1 Replies

10. Shell Programming and Scripting

Comparing 2 files and return the unique lines in first file

Hi, I have 2 files file1 ******** 01-05-09|java.xls| 02-05-08|c.txt| 08-01-09|perl.txt| 01-01-09|oracle.txt| ******** file2 ******** 01-02-09|windows.xls| 02-05-08|c.txt| 01-05-09|java.xls| 08-02-09|perl.txt| 01-01-09|oracle.txt| ******** (8 Replies)
Discussion started by: shekhar_v4
8 Replies
Login or Register to Ask a Question