Sponsored Content
Top Forums Shell Programming and Scripting csh: manipulating text files - please help! Post 302282306 by Torinator on Friday 30th of January 2009 01:36:18 PM
Old 01-30-2009
csh: manipulating text files - please help!

Hi All,
I am trying to manipulate a text file in a csh script I am writing. I just started scripting a few months ago and have NO idea how to get this to work. My ultimate goal is to turn a text file that looks like this:

4 ep2d_diff_mddw_20_p2-MOD err 128 128 64 62 52611737
2 MPRAGE ok 256 240 160 1 52616379
3 MPRAGERepeat ok 256 240 160 1 52615691
10 AxialPD-T2TSE ok 256 228 48 2 52607078
11 ep2d_bold_moco ok 64 64 36 120 52605446
12 ep2d_bold_moco ok 64 64 36 120 52604109
16 t2_spc_ns_sag_p2_da-fl_iso-MOD ok 256 256 176 1 52602792

Into this:

2 3danat MGZ 002.mgz
3 3danat MGZ 003.mgz
4 diff MGZ 004.mgz
10 AxialPD MGZ 010.mgz
11 ge_funk MGZ 011.mgz
12 ge_funk MGZ 012.mgz
16 t2_space MGZ 016.mgz


Where always,

ep2d_diff_mddw_20_p2-MOD = diff
MPRAGE = 3danat
MPRAGERepeat = 3danat
AxialPD-T2TSE = AxialPD
ep2d_bold_moco = ge_funk
t2_spc_ns_sag_p2_da-fl_iso-MOD = t2_space

The big catch is that the numbers in the first column proceeding these "replacements" may differ between text files so it is impossible to hardcode for example: "2 MPRAGE" is always equal to "2 3danat" because sometimes it might be 3 MPRAGE instead.

So basically, I hope to find any suggestions for commands that might be useful in maintaining the first number in each line, using the second entry in the line to replace it with a new name, then inserting the words "MGZ" next in the line and finally using the number at the beginning of the line as a variable to insert into 00$var.mgz.

Is this even possible???? Or am I hoping for way too much? Smilie

Thanks so very very much!
Tori
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Manipulating two files

Hi Friends, I prefer to represent my problem with example. I have two files as below: file1.txt --------- abcd.....1234......XY abcd.....1235......XX abcd................. abcd...231236..1111YX abcd...241236..1112YY abcd...241237......YY abce.....1235......YY file2.txt ------- ... (4 Replies)
Discussion started by: rinku11
4 Replies

2. Shell Programming and Scripting

Manipulating a text file

hey guys, need ur expert help. m a core banker got stuck in someting techie and cant find a solution have manged to extract a file from oracle apps in a format that looks something like this... REC- A b c d x INV- A b... (6 Replies)
Discussion started by: komalkg
6 Replies

3. Shell Programming and Scripting

csh script for deleting extra spaces in text file

I am new to scripting and I needed to know if there would be an easy way to delete extra spaces in a text file. I have a file with three rows with 22 numbers each, but there is extra spaces between the numbers when it gets output by this program AFNI that I am using. What script would help delete... (2 Replies)
Discussion started by: hertingm
2 Replies

4. UNIX for Dummies Questions & Answers

Manipulating files

Hi Guys, I'm really new to Unix and Linux and other scripting languages but recently I hv been really enthusiatic about learning more to help out on my work. So I have a file with 3 columns. A sample of it looks like looks like this : K2_537841 AAATCAGCCGCAACATTTGC ... (7 Replies)
Discussion started by: pawannoel
7 Replies

5. Shell Programming and Scripting

reading from two files and manipulating the data

hi i have a file of the following format FILE1 5 937 8 1860 1850 1 683 2 1 129 2 2 5 938 8 1122 1123 1 20 520 4 1860 1851 1 5 939 8 1122 1124 1 20 521 4i have another file which... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

6. Shell Programming and Scripting

copying and manipulating files

im copying alot of files this is a script im trying to modify but not sure how to make it copy files without an extension and then add a .txt to them abc= #assuming the file does not have an end or extension foo='abc$' FROM=/user/share/doc TO=~/home/doc for grep $foo in... (3 Replies)
Discussion started by: elginmulizwa
3 Replies

7. Shell Programming and Scripting

Manipulating audio files server side

Hi All, I have next to zero knowledge on what I am about to ask so I will just ask it in plain English :) I am wondering how best to go about manipulating audio files server side. The manipulations required are join files one after the other, eg, audio1 + audio2 + audio3 + audio4 = audio5 ... (0 Replies)
Discussion started by: linuxgoat
0 Replies

8. Shell Programming and Scripting

Manipulating files

Not sure if the question posted in another forums can be moved by me.So posting the link here. https://www.unix.com/unix-advanced-expert-users/221425-shell-script-manipulate-files.html#post302795379 Need your help here. (1 Reply)
Discussion started by: vedanta
1 Replies

9. Programming

Python for text manipulating

Dear All, I am trying to write a python code for reading a fixed number of lines from a big file then save those pieces into another file as columns. I think sample file is necessary for understanding: Sample Input file: Epi. dist.(km)= 0.8100E+02 0.7466E-07 0.4942E-07 0.7133E-07 ... (10 Replies)
Discussion started by: johankor
10 Replies

10. Shell Programming and Scripting

Read variables from a text file for use in csh script

Hello, I have a text file (say, declarevars.txt) that contains multiple lines that are essentially meant to be variable declarations: set arr1 = (var1a var1b var1c) set arr2 = (var2a var2b var2c) . . . I want to be able to read this text file within a csh (sorry) script and have that... (2 Replies)
Discussion started by: arjaydj
2 Replies
suspend(1)							   User Commands							suspend(1)

NAME
suspend - shell built-in function to halt the current shell SYNOPSIS
sh suspend csh suspend ksh suspend DESCRIPTION
sh Stops the execution of the current shell (but not if it is the login shell). csh Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su. ksh Stops the execution of the current shell (but not if it is the login shell). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5) SunOS 5.10 15 Apr 1994 suspend(1)
All times are GMT -4. The time now is 09:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy