Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for a redundancy in two rows and insert value between them.

Status
Not open for further replies.

GradUser2010

Technical User
Oct 21, 2010
6
Hello all,

Thank you in advance for reading this.

I have a group of 190 text files which need to be imported into excel in a predictable manner. They need to be imported alternating between name and values, but sometimes the files do not have any associated values and the next row will go directly to another name.

What I need is a way to search two rows which have two titles back (letter back to back rather than a letter then a number) and insert a placeholder, such as a zero or - in the row between them.

Example of data as is:

L_ax_tri_2.nii.gz
35 420.000000 0.447698 0.088189 0.200144 0.584866
L_cc_tri_2.nii.gz
L_mid_tri_2.nii.gz
20 240.000000 0.488219 0.085022 0.310645 0.609517
L_thal_tri_2.nii.gz
14 168.000000 0.410736 0.099223 0.276966 0.580937
L_wak_tri_2.nii.gz
13 156.000000 0.392963 0.089811 0.208304 0.517843
R_ax_tri_2.nii.gz
R_cc_tri_2.nii.gz
R_mid_tri_2.nii.gz
19 228.000000 0.508231 0.064390 0.420404 0.636616
R_thal_tri_2.nii.gz
29 348.000000 0.449264 0.132066 0.261360 0.699130
R_wak_tri_2.nii.gz
14 168.000000 0.413163 0.096112 0.226829 0.558308
R_ax_tri_2.nii.gz
30 360.000000 0.424469 0.071653 0.283891 0.576231



Example of output data, ideally in a new file, keeping the original file intact.

L_ax_tri_2.nii.gz
35 420.000000 0.447698 0.088189 0.200144 0.584866
L_cc_tri_2.nii.gz
0
L_mid_tri_2.nii.gz
20 240.000000 0.488219 0.085022 0.310645 0.609517
L_thal_tri_2.nii.gz
14 168.000000 0.410736 0.099223 0.276966 0.580937
L_wak_tri_2.nii.gz
13 156.000000 0.392963 0.089811 0.208304 0.517843
R_ax_tri_2.nii.gz
0
R_cc_tri_2.nii.gz
0
R_mid_tri_2.nii.gz
19 228.000000 0.508231 0.064390 0.420404 0.636616
R_thal_tri_2.nii.gz
29 348.000000 0.449264 0.132066 0.261360 0.699130
R_wak_tri_2.nii.gz
14 168.000000 0.413163 0.096112 0.226829 0.558308
R_ax_tri_2.nii.gz
30 360.000000 0.424469 0.071653 0.283891 0.576231



I will be searching through many files in order to manipulate the ones that need editing.

Thanks for any guidance! I am not sure how to begin this processes!


 
Like this ?
Code:
awk 'NF==1{if(g)print 0;g=1}NF>1{g=0}1' /path/to/input >output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV, thanks for the help.


What is included in the "/path/to/input >output"


I am assuming that the first part is the full path to the directory with the 150 or so text files. What about the output? Is this a new filename of my choice or a directory?

I tried the following:


[fsl@localhost DataTest]$ awk 'NF==1{if(g)print 0;g=1}NF>1{g=0}1' /home/fsl/Desktop/DataTest >DataTest1.txt

awk: cmd. line:1: fatal: file `/home/fsl/Desktop/DataTest' is a directory



 
What is included in the "/path/to/input >output"
/path/to/input is the pathname of the file containing "Example of data as is:"
output is the pathname of the file that will receive "Example of output data, ideally in a new file"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top