Search the pattern and copy in to the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search the pattern and copy in to the file
# 1  
Old 04-09-2012
Debian Search the pattern and copy in to the file

my qn is i have one file hex.txt.it contains some junk data and some hexa valueslike
hex.txt
Code:
sdfjhjkh 0x1233jkfhgjfhgajk;gha 0xacdd
jkgahfjkgha;sjghajklgha;gh
aghfjkgh;a
0xccc jhfjkhsd ox23cd
0x456 jkhdfjhjkafh

like this now iwant a script like to separate the hex values and paste into the hexc.txt file ,will you plz help me how to do this

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-09-2012 at 04:10 AM.. Reason: code tags
# 2  
Old 04-09-2012
hey siva

try

Code:
grep -v 0x hex.txt

dat shul help i guess.
Moderator's Comments:
Mod Comment Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-09-2012 at 04:11 AM..
# 3  
Old 04-09-2012
@siva.hardwork: How do you want hexc.txt to look like? Do you want only the hex values or do you want the lines from hex.txt containing hex values?
# 4  
Old 04-09-2012
thanks nikhil for the reply
but it is not working..it is giving some lines of data ...but my expection is in hexc.txt file i want oly hex data like
Code:
0x12333
0xacdd
0xccc....like this...

will you plz help me

---------- Post updated at 12:28 AM ---------- Previous update was at 12:27 AM ----------

hi balajesuri
thanks for looking my issue..
yaa i want oly hex values oly

Last edited by Scrutinizer; 04-09-2012 at 04:12 AM.. Reason: code tags
# 5  
Old 04-09-2012
Code:
[user@host ~]$ cat input
sdfjhjkh 0x1233jkfhgjfhgajk;gha 0xacdd
jkgahfjkgha;sjghajklgha;gh
aghfjkgh;a
0xccc jhfjkhsd ox23cd
0x456 jkhdfjhjkafh
[user@host ~]$ perl -ne 'while (/(0x\w+)/g) { print "$1\n" }' input
0x1233jkfhgjfhgajk
0xacdd
0xccc
0x456
[user@host ~]$

# 6  
Old 04-09-2012
thanks alot balajesuri
is it in the perl right..
cant we write in shelll?means shell commands....
# 7  
Old 04-09-2012
Code:
grep -o '0x[^; ]*' input

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. UNIX for Beginners Questions & Answers

Copy pattern inside the file

Hi all, I have files and have a missing record. I need copy the existing record and mark those values up. For example in the below file 11048 is missing. I need to copy 22001 and copy those create the values for 11048. I have 120 set of files and I need to do that on all files. Note the... (8 Replies)
Discussion started by: arunkumar_mca
8 Replies

3. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

4. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

5. Shell Programming and Scripting

search a word and copy the file

Hi need help with a script or command My requirement is - I need to do a "ls -ltr tcserver*.syslog" files in /tmp, direct the output to a file ls -ltr tcserv*.syslog | grep "Jan 31" | awk '{printf "\n" $9}' > jandat.logs -Then open each file in above list and search for string/word,... (4 Replies)
Discussion started by: karghum
4 Replies

6. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

7. Shell Programming and Scripting

Search and copy to a new file-Help

Hi All, server16.na.in.com UNKNOWN ftpuser "CWD" dms-imrm/Delasco_Invoices_DayForward_Scan" 250 - server16.na.in.com UNKNOWN ftpuser "PWD" 257 - server16.na.in.com UNKNOWN ftpuser "CWD Private" 250 - server16.na.in.com UNKNOWN ftpuser "PWD" 257 - server16.na.in.com UNKNOWN... (7 Replies)
Discussion started by: Tuxidow
7 Replies

8. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

9. UNIX for Advanced & Expert Users

File extension search and copy

Hi need to know if we can write a shell script to find files for a particular format;s ie both .csv and .txt in a particular folder and then copy them to a new folder on a dialy basis. Does anyone know how this can be accomplished? Thanks, Sandeep (20 Replies)
Discussion started by: bsandeep_80
20 Replies

10. Shell Programming and Scripting

Search file for pattern and grab some lines before pattern

I want to search a file for a string and then if the string is found I need the line that the string is on - but also the previous two lines from the file (that the pattern will not be found in) This is on solaris Can you help? (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question