Hi Jim,
Thanks for the reply. The trouble is, that command is not preserving deliminators between $2 $3 etc. Maybe I should be a little more specific in what I am trying to do:
This is what my text file lookes like that I want to read line by line:
Text_file_1:
### SCAN ACQUISITION DATABASE: ###
#Headers: Protocol name, ok/err, Xdim, Ydim, Zdim, Nframes, unpack name, unpack format
# Martinos Center Protocols:
T1_MPRAGE_sag ok 256 256 128 1 3danat MGZ
T2TSEAXIAL ok 256 204 35 1 t2 MGZ
DIFFUSION_HighRes err 128 128 60 70 diff MGZ
T2_SPACE_sag_1mm_match ok 256 240 176 1 t2_space MGZ
T2_SPACE_sag_1mm_fl_match ok 256 240 176 1 t2_flair MGZ
MEMPRAGE_4e_p2_1mm_iso ok 256 256 176 1 memprage MGZ
gre_field_mapping ok 64 64 26 1 asl_field MGZ
PASL_PQII ok 64 64 26 121 asl MGZ
ge_funk-MR-Resting ok 64 64 26 191 ge_func MGZ
# VA Protocols:
MPRAGE ok 256 240 160 1 3danat MGZ
MPRAGERepeat ok 256 240 160 1 3danat MGZ
ep2d_diff_mddw_20_p2-MOD err 128 128 64 62 diff MGZ
AxialPD-T2TSE ok 256 228 48 2 AxialPD MGZ
ep2d_bold_moco ok 64 64 36 120 ge_func MGZ
ep2d_bold_mocoRepeat ok 64 64 36 120 ge_func MGZ
ep2d_bold_mocoFinger_tap ok 64 64 36 120 finger_tap MGZ
t2_spc_ns_sag_p2_da-fl_iso-MOD ok 256 256 176 1 t2_space MGZ
AXT2FLAIRFS ok 512 448 38 1 t2_flair MGZ
First, I only want to consider lines not starting with # (I assume using | grep -v "#"). I then want to use the first 6 entries from each line (seperated by tabs) in Text_file_1 to grep a line containing those same six entries in another Text_file_2. If it exists in the second file, I would like to print the entire line of the Text_file_2 into Text_file_3, but then use sed to replace some things.
Example:
Each Text_file_1 line:
MPRAGE ok 256 240 160 1 3danat MGZ
"MPRAGE ok 256 240 160 1" is then pulled out to grep within Text_file_2:
2 MPRAGE ok 256 240 160 1 30793230
3 MPRAGERepeat ok 256 240 160 1 30792546
4 ep2d_diff_mddw_20_p2-MOD err 128 128 64 62 30788600
10 AxialPD-T2TSE ok 256 228 48 2 30783957
11 ep2d_bold_moco ok 64 64 36 120 30782329
12 ep2d_bold_moco ok 64 64 36 120 30780996
16 ep2d_bold_mocoRepeat ok 64 64 36 120 30779689
17 ep2d_bold_mocoRepeat ok 64 64 36 120 30775121
21 ep2d_bold_mocoFinger_tap ok 64 64 36 120 30773814
22 ep2d_bold_mocoFinger_tap ok 64 64 36 120 30772481
26 t2_spc_ns_sag_p2_da-fl_iso-MOD ok 256 256 176 1 30771174
27 AXT2FLAIRFS ok 512 448 38 1 30767585
Since the first line of Text_file_2 matches, I want to then print it into a new textfile in the following format:
2 MPRAGE ok 256 240 160 1 30793230 (Text_file_2)
combined with
MPRAGE ok 256 240 160 1 3danat MGZ (text_file_1)
To create a new file with a line that looks like this:
2 3danat MGZ 002.mgz
I am more familiar with csh, but I cannot find a way to use a text file line by line using csh. Therefore, my idea is to call a bash script within my csh script to make my new text file. I don't even know if that will work. I really apologize if this is confusing. If I am not being clear, I can go back to the old way of doing things. I'm just trying to find a way not to hard code a script.
Thanks again!
Tori