Help with rename header content based on reference file problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with rename header content based on reference file problem
# 1  
Old 12-10-2010
Help with rename header content based on reference file problem

I got long list of reference file
Code:
>data_tmp_number_22
>data_tmp_number_12
>data_tmp_number_20
.
.

Input file:
Code:
>sample_data_1 Math, 5, USA, tmp
SDFEWRWERWERWRWER
FSFDSFSDFSDGSDGSD
>sample_data_2 Math, 15, UK, tmp
FDSFSDFF
>sample_data_3 Math, 50, USA, tmp
ARQERREQR
.
.

Desired output:
Code:
>data_tmp_number_22
SDFEWRWERWERWRWER
FSFDSFSDFSDGSDGSD
>data_tmp_number_12
FDSFSDFF
>data_tmp_number_20
ARQERREQR
.
.

My purpose just wants to replace all the input file header becomes the header of reference file.
Any programming language will be appreciated.
Thanks.

Last edited by perl_beginner; 12-23-2010 at 06:05 AM..
# 2  
Old 12-10-2010
Code:
cat Input_File | paste - Ref_File - | awk '{print $2RS$3}'

Code:
# cat input
>data_1
SDFEWRWERWERWRWER
>data_2
FDSFSDFF
>data_3
ARQERREQR

Code:
# cat ref
>AAADF
>RTHQ
>FDSF

Code:
# cat input | paste - ref - | awk '{print $2RS$3}'
>AAADF
SDFEWRWERWERWRWER
>RTHQ
FDSFSDFF
>FDSF
ARQERREQR

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 12-23-2010
Hi ctsgnb,
I just try your command.
It seems like facing error when dealing with replacement long list of data?
# 4  
Old 12-23-2010
Code:
paste -d"|" ref input | tr '|' '\n'

This User Gave Thanks to For This Post:
R0H0N
# 5  
Old 12-23-2010
thanks, ROHON.
I just edit my post with another example.
Do you have any idea to solve the problem?
# 6  
Old 12-23-2010
is there any particular defined patterns of header and other lines in input file, so that I can recognize whether line is a header or a normal line?
R0H0N
# 7  
Old 12-23-2010
If lines in inputFile to be replaced always starting with character > then:
Code:
awk 'NR==FNR{a[NR]=$0;next;}{if(a[i] && substr($0,1,1)==">"){$0=a[i];i++;}print;}' i=1 codeFile inputFile

This will replace all lines in inputFile which starts with charater >

Last edited by anurag.singh; 12-23-2010 at 09:10 AM..
This User Gave Thanks to anurag.singh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Keeping record of file 2 based on a reference file 1 in awk

I have 2 input files (tab separated): file1: make_A 1990 foo bar make_B 2010 this that make_C 2004 these those file2: make_X 1970 1995 ref_1:43 ref_2:65 make_A 1970 1995 ref_1:4 ref_2:21 ref_3:18 make_A 1980 2002 ref_1:7 ref_2:7 ref_3:0 ... (2 Replies)
Discussion started by: beca123456
2 Replies

2. Shell Programming and Scripting

awk : split file and rename and save in path according to content

Hello, I'm using Windows 7 ; sed, awk and gnuwin32 are installed. I have a big text file I need to manipulate. In short, I will have to split it in thousands of short files, then rename and save in a folder which name is based upon filename. Here is a snippet of my big input.txt file (this... (4 Replies)
Discussion started by: sellig
4 Replies

3. Shell Programming and Scripting

Print the column content based on the header

i have a input of csv file as below but the sequence of column get changed. I,e it is not necessary that name comes first then age and rest all, it may vary. name,age,marks,roll,section kevin,25,80,456,A Satch,23,56,789,B Meena,24,78,H245,C So i want to print that column entires which... (12 Replies)
Discussion started by: millan
12 Replies

4. Shell Programming and Scripting

Remove the file content based on the Header of the file

Hi All, I want to remove the content based on the header information . Please find the example below. File1.txt Name|Last|First|Location|DepId|Depname|DepLoc naga|rr|tion|hyd|1|wer|opr Nava|ra|tin|gen|2|wera|opra I have to search for the DepId and remove the data from the... (5 Replies)
Discussion started by: i150371485
5 Replies

5. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (1 Reply)
Discussion started by: perl_beginner
1 Replies

6. Shell Programming and Scripting

Help with replace column one content based on reference file

Input file 1 testing 10 20 1 A testing 20 40 1 3 testing 23 232 2 1 testing 10 243 2 . . Reference file 1 final 3 used . . Output file (2 Replies)
Discussion started by: perl_beginner
2 Replies

7. UNIX for Dummies Questions & Answers

Changing file content based on file header

Hi, I have several text files each containing some data as shown below: File1.txt >DataHeader Data... Data... File2.txt >DataHeader Data... Data... etc. What I want is to change the 'DataHeader' based on the file name. So the output should look like: File1.txt >File1 ... (1 Reply)
Discussion started by: Fahmida
1 Replies

8. Shell Programming and Scripting

Replace character based on reference file problem asking

I got two files right now, input file (target file), reference file 1 (query file) reference file 1 (long list of data) KOLOPWMOPOPO ADASDASD ADSASDASDAD . . target file (one long liner content) ADASDASDTYUKOKOLOPWMOPOPOOPLUAADSASDASDADPOPOUYADADASDASD desired output file content ... (1 Reply)
Discussion started by: patrick87
1 Replies

9. Shell Programming and Scripting

Extract specific content from data and rename its header problem asking

Input file 1: >pattern_5 GAATTCGTTCATGTAGGTTGASDASFGDSGRTYRYGHDGSDFGSDGGDSGSDGSDFGSDF ATTTAATTATGATTCATACGTCATATGTTATTATTCAATCGTATAAAATTATGTGACCTT SDFSDGSDFKSDAFLKJASLFJASKLFSJAKJFHASJKFHASJKFHASJKFHSJAKFHAW >pattern_1 AAGTCTTAAGATATCACCGTCGATTAGGTTTATACAGCTTTTGTGTTATTTAAATTTGAC... (10 Replies)
Discussion started by: patrick87
10 Replies

10. Shell Programming and Scripting

Remove specific pattern header and its content problem facing

Input file: >TRACK: Position: 1 TYPE: 1 Pos: SVAVPQRHHPGGTVFREPIIIPAIPRLVPGWNKPIIIGRHAFGDQYRATDRVIPGPGKLE LVYTPVNGEPETVKVYDFQGGGIAQTQYNTDESIRGFAHASFQMALLKGLPLYMSTKNTI LKRYDGRFKDIFQEIYESTYQKDFEAKNLWYEHRLIDDMVAQMIKSEGGFVMALKNYDGD >TRACK: Position: 1 TYPE: 2 Pos: FAHASFQMALLKGLPLYMS... (8 Replies)
Discussion started by: patrick87
8 Replies
Login or Register to Ask a Question