Inserting information from old text file into a new text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Inserting information from old text file into a new text file
# 1  
Old 10-20-2014
Inserting information from old text file into a new text file

Hello, I'm trying to take information from a list of hundreds of subject ids (where each line is a new subject id), and insert each line into a new text file that contains the pathnames for each subject.

To clarify, all subject have a similiar path name (e.g., C:\data\SUBJECT_ID\) that contains .img and .txt files for each subject. I want unix to create a new text file with 3 columns: the path to the subject's text file, the path to the subject's image file, and the subject id. After searching for some solutations, I have tried using a foreach loop to read each subject id from the id list, and insert each id name into the three columns of the new text file. Here's what I have been playing with:
Code:
foreach dir ( 'subjectlist.txt' )
echo
c:/data/$dir/$dir"g7.img" c:/data/$dir/mask.txt $dir > newfile.txt
end

This returns the subject ids, followed by "command not found". Essentially, I want to replace $dir with the subject id for everybody.

Please let me know if this isn't clear, I'm very new to unix and have been stuck on this for days, and I'd greatly appreciate any help!!


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 10-20-2014 at 12:15 PM..
# 2  
Old 10-20-2014
???
What shell and OS you are talking about because here it looks like DOS...
This User Gave Thanks to vbe For This Post:
# 3  
Old 10-20-2014
I'm using csh in linux.
# 4  
Old 10-21-2014
Didnt fully understand your question , the solution is built on guesses

Code:
 
cat test8
sub1
sub2
sub3
 
awk -v pathvar1="C:/data" '{ print pathvar1"/"$0"/"$0".img""\t"pathvar1"/"$0"/"$0".txt""\t"$0}' test8
C:/data/sub1/sub1.img C:/data/sub1/sub1.txt sub1
C:/data/sub2/sub2.img C:/data/sub2/sub2.txt sub2
C:/data/sub3/sub3.img C:/data/sub3/sub3.txt sub3

This User Gave Thanks to senhia83 For This Post:
# 5  
Old 10-21-2014
Thanks for the suggestions. I wasn't able to get it to work right with awk, but I finally got it to work with a while loop:

Code:
while read line;
do echo c:/data/$line/$line"g7.img" c:/data/$line/tmask.txt $line; done < subjectlist.txt > subjectfilepaths.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Inserting IDs from a text file into a sequence alignment file

Hi, I have one file with one column and several hundred entries File1: NA1 NA2 NA3And now I need to run a command within a mapping aligner tool to insert these sample names into a sequence alignment file (SAM) such that they look like this @RG ID:Library1 SM:NA1 PL:Illumina ... (7 Replies)
Discussion started by: nans
7 Replies

3. Shell Programming and Scripting

Inserting text in file names while copying them.

I'm trying to find a Bourne shell script that will copy files from one directory using a wild card for the file name (*) and add some more characters in the middle of the file name as it is copied. As an example: /u01/tmp-file1.xml => /u02/tmp-file1-20130620.xml /u01/tmp-file2.xml => ... (6 Replies)
Discussion started by: Tony Keller
6 Replies

4. UNIX for Dummies Questions & Answers

Inserting text into a file with awk or sed

Hello, I've been trying to get a script working that fetches weather-data and converts it into an .ics file. The script works so far put I'm stuck at the point where I need to add specific static data. A thorough search through the forum did not point me into the right direction. #!/bin/bash... (3 Replies)
Discussion started by: Schubi
3 Replies

5. Shell Programming and Scripting

Help with sed and inserting text from another file

I need to insert text from one file into another file after specific term. I guess sed is the best method of doing this and I can insert a specified text string using this script but I am not sure how to modify it to insert text from another file: #!/bin/sh sed 's/\<VirtualHost... (17 Replies)
Discussion started by: barrydocks
17 Replies

6. Shell Programming and Scripting

Inserting text into a new file

Hi all, I want to create a file and then insert some text into it. I'm trying to create a .sh script that will create a new python file from a template. Can someone tell me why this won't work, touch $1 | sed -e '1i\Some test code here' Sorry I'm quite new to all this! Just as a side... (3 Replies)
Discussion started by: ahodgson
3 Replies

7. UNIX for Dummies Questions & Answers

Inserting a column into a text file

I have a tab delimited text file with multiple columns (data.txt). I would like to insert a column into the text file. The column I want to insert is in a text file (column.txt). I want to insert it into the 5th column of data.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

8. Shell Programming and Scripting

inserting a string to a text file

Hello Can somebody please help me with the following script? I'm trying to create a text file with 20 blank lines and then insert a string in line 2 but nothing is printed in the itxtfile. I can create the file with 20 blank lines but when I "tell" it to print something on the second line, it... (4 Replies)
Discussion started by: goude
4 Replies

9. Shell Programming and Scripting

Inserting text and modifying the file

I am in a dire need of doing this job , please help from shell script or perl script. It will be highly appreciated. Please have a look at the following INPUT file; The first 14 rows are not of interest but I want them to be included in the output file as they are. From the row 14... (3 Replies)
Discussion started by: digipak
3 Replies

10. Shell Programming and Scripting

inserting subscriber no in text file using KSH....

:confused:Dears , I have text file I need to insert the subscriber number at position 32, and need to keep the next field at position 53 (no increasing of the record lenght), I mean I just want to replace the spaces at position 32 with subscirber number . for example A B A ... (1 Reply)
Discussion started by: atiato
1 Replies
Login or Register to Ask a Question