04-20-2009
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
Last edited by Torinator; 04-20-2009 at 03:40 PM..
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
2. Shell Programming and Scripting
Hi Masters,
Iam new to this Forum and this is my first post.
My question is:
I've some datafiles belongs the type (A, B, C) in the location 'export/home/lokiman '
dataA1.txt
dataB28.txt
dataC35.txt
1) I've to check the read permission for each file, if it not there then I've to... (1 Reply)
Discussion started by: lokiman
1 Replies
3. Shell Programming and Scripting
Hi,
I need a command in UNIX KSH below is the description...
MAPPING DESCRIPTION ="Test Mapping for the calid inputs" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"
unix ksh command to read the DESCRIPTION and write to a file
Test Mapping for the calid inputs... (3 Replies)
Discussion started by: perlamohan
3 Replies
4. Shell Programming and Scripting
Hallo,
i need a Prompting read in my script:
read -p "Enter your command: " command
But i always get this Error:
-p: is not an identifier
When I run these in c-shell i get this error
/usr/bin/read: read: bad option(s)
How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies
5. Shell Programming and Scripting
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Discussion started by: shis100
7 Replies
6. Programming
Hi,
I have a string like this,
char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line";
if I want to use strtok() to seperate the string, which token should I use?
I tried "\n", "\\n", either not working.
peter (1 Reply)
Discussion started by: laopi
1 Replies
7. Shell Programming and Scripting
I have to pull multiple line records with ^ as the record separator(RS)... # should be my field separator (FS)...
Sample record is:
^-60#ORA-00060: deadlock detected while waiting for resource
ORA-00001: unique constraint (SARADM.TCKNUM_PK) violated#PROC:AVAILABLE_FOR_GETNXTTIC#02/27/2012... (7 Replies)
Discussion started by: Vidhyaprakash
7 Replies
8. Shell Programming and Scripting
Legends,
i am using while to read 4 colums from a file.
but the while loop exits after reading 1st column.
please let me know, how to reach till end of the file.
FILE CONTENT
birdiex1:/home/s/sandeepk/scripts> vi /tmp/gleod_time
"/tmp/gleod_time"
03_upd_stat_tbl_birdiex1 ... (2 Replies)
Discussion started by: sdosanjh
2 Replies
9. UNIX for Dummies Questions & Answers
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies
10. Shell Programming and Scripting
Hi everybody,
I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o
My code:
#!/bin/sh
set -e
set -u
export IFS=
optl="Optl"
LOCSTORCLI="/opt/lsi/storcli/storcli"
($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
RESIZE(1) General Commands Manual RESIZE(1)
NAME
resize - set environment and terminal settings to current xterm window size
SYNOPSIS
resize [ -u | -c ] [ -s [ row col ] ]
DESCRIPTION
Resize prints a shell command for setting the appropriate environment variables to indicate the current size of xterm window from which the
command is run. For this output to take effect, resize must either be evaluated as part of the command line (usually done with a shell
alias or function) or else redirected to a file which can then be read in. From the C shell (usually known as /bin/csh), the following
alias could be defined in the user's .cshrc:
% alias rs 'set noglob; eval `resize`'
After resizing the window, the user would type:
% rs
Users of versions of the Bourne shell (usually known as /bin/sh) that don't have command functions will need to send the output to a tempo-
rary file and then read it back in with the "." command:
$ resize > /tmp/out
$ . /tmp/out
Resize determines the user's current shell by first checking if $SHELL is set, and using that. Otherwise it determines the user's shell by
looking in the password file. Generally Bourne-shell variants (including ksh) do not modify $SHELL, so it is possible for resize to be
confused if one runs resize from a Bourne shell spawned from a C shell.
OPTIONS
The following options may be used with resize:
-u This option indicates that Bourne shell commands should be generated even if the user's current shell isn't /bin/sh.
-c This option indicates that C shell commands should be generated even if the user's current shell isn't /bin/csh.
-s [rows columns]
This option indicates that Sun console escape sequences will be used instead of the VT100-style xterm escape codes. If rows and
columns are given, resize will ask the xterm to resize itself. However, the window manager may choose to disallow the change.
Note that the Sun console escape sequences are recognized by XFree86 xterm and by dtterm. The resize program may be installed as sunsize,
which causes makes it assume the -s option.
The rows and columns arguments must appear last; though they are normally associated with the -s option, they are parsed separately.
FILES
/etc/termcap for the base termcap entry to modify.
~/.cshrc user's alias for the command.
ENVIRONMENT
TERM set to "xterm" if not already set.
TERMCAP variable set on systems using termcap
COLUMNS, LINES variables set on systems using terminfo
SEE ALSO
csh(1), tset(1), xterm(1)
AUTHORS
Mark Vandevoorde (MIT-Athena), Edward Moy (Berkeley)
Copyright (c) 1984, 1985 by X Consortium
See X(7) for a complete copyright notice.
X Window System RESIZE(1)