10-12-2009
parsing text three fields at a time
I'm programming in csh and I have a text file with hundreds of entries seperated only by spaces. I want to access three fields at a time (as each data set has three components) so that I can send these values to a different routine as three variables until every trio of values in the text file has been processed. The problem is I don't seem to have permission to use the 'read' or 'open' commands on my system (they aren't in my path or I can't copy them into my path because of permissions).
I tried creating an array: set temp = `cat file.txt` but then I can't figure out how to iterate through the array to get three values from it at once without "read" or "open" in a while loop...help? Once again, I'm pretty sure "read" and "open" aren't being recognized as commands.
When I try foreach line ($temp) it only references each individual entry and not a full line.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Can someone tell me how to do this using sed, awk, or any other basic shell scripting? Basically I have two text files with the following contained in each file:
File A:
a b c
d e f
g h i
File B:
1
2
3
I want the final outcome to look like this:
a b c 1
d e f 2
g h i 3
How... (3 Replies)
Discussion started by: shocker
3 Replies
2. Shell Programming and Scripting
I have a file that is large and is broken up by groups of data. I want to take certain fields and display them different to make it easier to read. Given input file below:
2008 fl01 LAC 2589 polk doal
xx 2008q1 mx
sect 25698541
Sales 08 Dept group
lead1 ... (8 Replies)
Discussion started by: timj123
8 Replies
3. Shell Programming and Scripting
Hi,
Currently I am coding up a nasty way of reading file input using *cat* rather than *read*. My text input looks like
TextA 100
TextB 110
TextC 120
Currently I am using cat |while read line to read the first column and second column fields.
cat foo.txt|while read line
do
... (1 Reply)
Discussion started by: ahjiefreak
1 Replies
4. Shell Programming and Scripting
Hello all,
I have some text formatted as follows
Name: John doe
Company:
Address 1: 7 times the headache
Address 2:
City: my city
State/Province: confusion
Zip/Postalcode: 12345
and I'm trying to figure out how I could extract the data after the colon so that the result would be ... (6 Replies)
Discussion started by: mcgrailm
6 Replies
5. Shell Programming and Scripting
I'm trying to write a script that will parse the output of the iostat command in real time and place the output in csv file(s). I do have a programming background, but am relatively new to shell so I'm having difficulties determining how to proceed.
The cpu stats will go into one output... (6 Replies)
Discussion started by: fastergrace
6 Replies
6. Shell Programming and Scripting
Hello
I have a file that contains 10 rows as below:
"ID" "DP"
"ID=GRMZM2G015073_T01" "23.6044288292005"
"ID=GRMZM2G119852_T01" "59.7782287606723"
"ID=GRMZM2G100242_T02" "61.4167813736184"
"ID=GRMZM2G046274_T01" "6.63061838134219"
"ID=GRMZM2G046274_T02" ... (5 Replies)
Discussion started by: cs_novice
5 Replies
7. Shell Programming and Scripting
Hello I am trying to develop a shell script that takes a text file such as this...
E-mail@ Soc.Sec.No. *--------Name-----------* Class *School.Curriculum.Major.* Campus.Phone
JCC2380 XXX-XX-XXXX CAREY, JULIE C JR-II BISS CPSC BS INFO TECH 412/779-9445
JAC1936 XXX-XX-XXXX... (7 Replies)
Discussion started by: crimputt
7 Replies
8. Shell Programming and Scripting
Hi All!
Is it possible to convert text file:
to:
? (6 Replies)
Discussion started by: y77
6 Replies
9. Shell Programming and Scripting
A record contains 50 fields separated by "~". I need to assign each of these fields to different variables. Following is the shell script approach I tried.
RECORD="FIELD1~FIELD2~FIELD3~FIELD4~FIELD5~...........~FIELD50"
VAR1=$(echo ${RECORD} | cut -d"~" -f 1)
VAR2=$(echo ${RECORD} | cut... (5 Replies)
Discussion started by: krishmaths
5 Replies
10. UNIX for Beginners Questions & Answers
I am trying to work on a script to grab the UTC time from a website
So far I was able to cobble this together.
curl -s --head web-url | grep ^Date: | sed 's/Date: //g'
Which gives me the result I need.
Wed, 06 Dec 2017 21:43:50 GMT
What I need to is extract the 21:43:50 and convert... (4 Replies)
Discussion started by: allisterB
4 Replies
OPEN(5) File Formats Manual OPEN(5)
NAME
open, create - prepare a fid for I/O on an existing or new file
SYNOPSIS
Topen tag[2] fid[2] mode[1]
Ropen tag[2] fid[2] qid[8]
Tcreate tag[2] fid[2] name[28] perm[4] mode[1]
Rcreate tag[2] fid[2] qid[8]
DESCRIPTION
The open request asks the file server to check permissions and prepare a fid for I/O with subsequent read and write messages. The mode
field determines the type of I/O: 0, 1, 2, and 3 mean read access, write access, read and write access, and execute access, to be checked
against the permissions for the file. In addition, if mode has the OTRUNC (0x10) bit set, the file is to be truncated, which requires
write permission (if the file is append-only, and permission is granted, the open succeeds but the file will not be truncated); if the mode
has the ORCLOSE (0x40) bit set, the file is to be removed when the fid is clunked, which requires permission to remove the file from its
directory. If other bits are set in mode they will be ignored. It is illegal to write a directory, truncate it, or attempt to remove it
on close. If the file is marked for exclusive use (see stat(5)), only one client can have the file open at any time. That is, after such
a file has been opened, no other open will succeed until fid has been clunked. All these permissions are checked at the time of the open
request; subsequent changes to the permissions of files do not affect the ability to read, write, or remove an open file.
The create request asks the file server to create a new file with the name supplied, in the directory (dir) represented by fid, and
requires write permission in the directory. The owner of the file is the implied user id of the request, the group of the file is the same
as dir, and the permissions are the value of
(perm&(~0777|0111)) | (dir.perm&perm&0666)
if a regular file is being created and
(perm&~0777) | (dir.perm&perm&0777)
if a directory is being created. This means, for example, that if the create allows read permission to others, but the containing direc-
tory does not, then the created file will not allow others to read the file.
Finally, the newly created file is opened according to mode, and fid will represent the newly opened file. Mode is not checked against the
permissions in perm. The qid for the new file is returned with the create reply message.
Directories are created by setting the CHDIR bit (0x80000000) in the perm.
The names . and .. are special; it is illegal to create files with these names.
It is an error for either of these messages if the fid is already the product of a successful open or create message.
An attempt to create a file in a directory where the given name already exists will be rejected; in this case, the create system call (see
open(2)) uses open with truncation. The algorithm used by create is: first walk to the directory to contain the file. If that fails,
return an error. Next walk to the specified file. If the walk succeeds, send a request to open and truncate the file and return the
result, successful or not. If the walk fails, send a create message. If that fails, it may be because the file was created by another
process after the previous walk failed, so (once) try the walk and open again. For the behavior of create on a union directory, see
bind(2).
ENTRY POINTS
Open and create both generate open messages; only create generates a create message.
OPEN(5)