Match only a-fA-F0-9 in a file

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Match only a-fA-F0-9 in a file
# 1  
Old 12-28-2015
Match only a-fA-F0-9 in a file

Hi,

I have a big file of hashes, but some lines are complete garbage and do not match with hexadecimal caracters.

I would like to use sed to select only the lines thar are composed by a-fA-F0-9 and print them into an outside file.

I tried
Code:
sed '/.[a-f0-9A-F]\{32\}/p' myFile > myNewFile

but it didn't work. Do you have any idea ?

Thank you Smilie

Last edited by ganon551; 12-28-2015 at 02:54 AM..
# 2  
Old 12-28-2015
Since you did not post any example of input or output, but rather just the not working regular expression, this is only a guess:
Drop the . (dot) in front of it. If that does not fix it, please, tell us in what way is not working, and show us some input and output.
# 3  
Old 12-28-2015
Hello ganon551,

Please use code tags for commands/codes/Input you have shown in your posts as per forum rules. Also please do show us the sample input with expected output which will help us to understand your requirement in better manner, based on some assumptions following may help you in same, not sure is there any specific reason for using sed by you, why don't you give a try to simple grep too.
Let's say we have following Input_file:
Code:
cat Input_file
TestSingha-fA-F0-9test2
a-fA-F0-91233445667
test12334567
R. Singh is a bad boy.
Iron man is my hero.
Love you UNIX.com
a-fA-F0-9

Following will be the command then for same.
Code:
grep "a-fA-F0-9" Input_file > Output_file

You will see the output in Output_file as follows.
Code:
cat Output_file
TestSingha-fA-F0-9test2
a-fA-F0-91233445667
a-fA-F0-9

Thanks,
R. Singh
# 4  
Old 12-28-2015
Whoops you're right sorry.

I tried without the dot and then added it.

So I have things like this as input :

Code:
$7.PxCsOF/tXBo7HR/0Tpxixk2i3eFs/
$7.qGSerhC8121ktlsaYhjFw2o53mkH/
45fd7bbdb5be9b735e8e85792e215177
45fd84989fb0897547529a123942a289
45fd91a6031d64f59c0bae8efb3ce4ca
45fd9ee96f4f19f31c9418bbfc65afac
45fdd39340740ca502d0f669bd5d604a
nlGwAUMrLpD3u5qUPh5Lz0xwenuxO5YU
o1j5n72bXKQToeCTLLv2lGV7QqBJM1vg
og4Q7tsiYxAEiqplF6vTABSnP4fqlfmO

And I want to output this :

Code:
45fd7bbdb5be9b735e8e85792e215177
45fd84989fb0897547529a123942a289
45fd91a6031d64f59c0bae8efb3ce4ca
45fd9ee96f4f19f31c9418bbfc65afac
45fdd39340740ca502d0f669bd5d604a

Onlye the lines that are composed with hexadecimal caracters.

Thank you for your reply.
# 5  
Old 12-28-2015
Code:
sed -n '/[a-f0-9A-F]\{32\}/p' input
45fd7bbdb5be9b735e8e85792e215177
45fd84989fb0897547529a123942a289
45fd91a6031d64f59c0bae8efb3ce4ca
45fd9ee96f4f19f31c9418bbfc65afac
45fdd39340740ca502d0f669bd5d604a

# 6  
Old 12-28-2015
I forgot the -n option you're right. It's working now.

Thank you for your fast replies guys Smilie
And have a good new year !
# 7  
Old 12-28-2015
Hello ganon551,

You could try an awk solution too for same.
Code:
awk --re-interval '{match($0,/[a-fA-F0-9]{32}/);if(substr($0,RSTART,RLENGTH)){print}}' Input_file

Output will be as follows.
Code:
45fd7bbdb5be9b735e8e85792e215177
45fd84989fb0897547529a123942a289
45fd91a6031d64f59c0bae8efb3ce4ca
45fd9ee96f4f19f31c9418bbfc65afac
45fdd39340740ca502d0f669bd5d604a

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

2. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Discussion started by: cmccabe
4 Replies

5. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

6. Shell Programming and Scripting

Help with ksh-to read ip file & append lines to another file based on pattern match

Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies

7. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

8. UNIX for Dummies Questions & Answers

Help with AWK - Compare a field in a file to lookup file and substitute if only a match

I have the below 2 files: 1) Third field from file1.txt should be compared to the first field of lookup.txt. 2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt. 3)Else just print the line from file1.txt. File1.txt:... (4 Replies)
Discussion started by: venalla_shine
4 Replies

9. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

10. Shell Programming and Scripting

How to find first match and last match in a file

Hi All, I have a below file: ================== 02:53 pravin-root 02:53 pravin-root 03:05 pravin-root 02:55 pravin1-root 02:59 pravin1-root ================== How do I find the first and last value of column 1. For example, how do I find 02:53 is the first time stamp and 03:05 is... (3 Replies)
Discussion started by: praving5
3 Replies
Login or Register to Ask a Question