07-15-2009
don't use $/
try reading whole thing as a string, use split to get whwat you need instead
$/ is for cutting streams. It isn't even a string until you place it into a register.
or use it to slurp the whole file into a variable.
Example
open (FILE, "$filename");
local $/;
$file=<FILE>;
close(FILE);
#the entire file is in one variable including the [
@file=split("[", $file);
#now it is in an array.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
all: $(LIBRARY) $(EXE)
$(MAKEMAKE):
@rm -f $(MAKEMAKE)
$(PURIFY) $(CXX) -M $(INCLUDE) $(CPPFLAGS) *.cpp > $(MAKEMAKE)
$(EXE): $(OBJS) $(LIBRARY)
@echo "Creating a executable "
$(PURIFY) $(CC) -o $(EXE) $(OBJS) $(ALLLDFLAGS) $(LIBS)
This is a snippet... (2 Replies)
Discussion started by: laila63
2 Replies
2. UNIX for Dummies Questions & Answers
can some one give me a list of unix separtor(s) if one than just the separator please thank you. (2 Replies)
Discussion started by: Black mage2021
2 Replies
3. Shell Programming and Scripting
is there a similar parameter you can set in perl like FS in awk?
I think I've read all the tutorials on the subject, but cannot get this map split and so on thing to work.
I need to sort a file by columns, eg. first, third, fifth...
The script I need to add this column sorting is this:
use... (38 Replies)
Discussion started by: ahsog
38 Replies
4. Shell Programming and Scripting
I have tried to use ">" as record separator, but it doesn't work.
I have tried this:
awk BEGIN{RS=">"}'{print $0}' input
output:
awk: BEGIN{RS=>}{print $0}
awk: ^ syntax error
awk BEGIN{RS="\>"}'{print $0}' input
awk: BEGIN{RS=\>}{print $0}
awk: ^ backslash not... (2 Replies)
Discussion started by: locoroco
2 Replies
5. Shell Programming and Scripting
Hi,
I have a flat file with fields separated by a X'1F'
i have to fetch 4th field from second line.
please help me how to achieve it.
I tried with below command and its not working.
cut -f4 -d`echo -e '\x1f'` filename.txt
I am using SunOS.
Thanks in advance. (2 Replies)
Discussion started by: rohan10k
2 Replies
6. Shell Programming and Scripting
It shows error at 'else', how can I fix it?
if ; then # Note the space after the semicolon.
#+ ^^
echo "File $filename exists."; cp $filename $filename.bak
else # ^^
echo "File $filename not found."; touch $filename
fi; echo "File test complete." (3 Replies)
Discussion started by: Qazi
3 Replies
7. Shell Programming and Scripting
Hello All,
I need help with the below, I would appreciate any tip.
I have a file as below
Input file
Apple: Green
Banana: Yellow
Grapes: Black
Apple: Red
Banana: Green
Grapes: Green
Grapes: Brown
Apple: Pale Red
Banana: Greenish yellow
Grapes: Brown
Apple: Yellowish... (14 Replies)
Discussion started by: m6248m
14 Replies
8. Shell Programming and Scripting
Hello All,
I have a file, but I want to separate the file at a particular record with comma"," in the line
Input file
APPLE6SSAMSUNGS5PRICEPERPIECEDOLLAR600EACH010020340URX581949695US
to
Output file
APPLE6S,SAMSUNGS5,PRICEPERPIECE,DOLLAR600EACH,010020340URX581949695,US
This is for... (11 Replies)
Discussion started by: m6248m
11 Replies
9. Shell Programming and Scripting
Friends have the following code that is correct.
BEGIN { num_reg = 0
suma_iva=0
}
{
num_reg++
suma_iva=suma_iva+int(substr($0, 103,9))
}
END{
printf ("%011d",suma_iva)
}
I have the following problem, I have to do just that but this time... (4 Replies)
Discussion started by: tricampeon81
4 Replies
10. Shell Programming and Scripting
Hello everybody, I'll get one more help
I have a cabundle file that I need to separate into 2 parts, the first sequence and the second sequence, I thought of several things but I did not remember anything that could actually accomplish this separation and transform into 2 variables, first... (4 Replies)
Discussion started by: c0i0t3
4 Replies
LEARN ABOUT ULTRIX
fdopen
fopen(3s) fopen(3s)
Name
fopen, freopen, fdopen - open a stream
Syntax
#include <stdio.h>
FILE *fopen (filename, type)
char *filename, *type;
FILE *freopen (filename, type, stream)
char *filename, *type;
FILE *stream;
FILE *fdopen (fildes, type)
int fildes;
char *type;
Description
The routine opens the file named by filename and associates a stream with it. The routine returns a pointer to the FILE structure associ-
ated with the stream.
The filename points to a character string that contains the name of the file to be opened.
The type is a character string having one of the following values:
"r" Open for reading
"w" Truncate or create for writing
"a" Append; open for writing at end of file, or create for writing
"A" Append with no overwrite; open for writing at end-of-file, or create for writing
"r+" Open for reading and writing
"w+" Truncate or create for reading and writing
"a+" Append; open or create for reading and writing at end-of-file
"A+" Append with no overwrite, open or create for update at end-of-file
The letter "b" can also follow r, w, or a. In some C implementations, the "b" is needed to indicate a binary file, however, it is not
needed in ULTRIX. If "+" is used, the "b" may occur on either side, as in "rb+" or "w+b".
The routine substitutes the named file in place of the open stream. The original stream is closed, regardless of whether the open ulti-
mately succeeds. The routine returns a pointer to the FILE structure associated with stream.
The routine is typically used to attach the preopened streams associated with stdin, stdout and stderr to other files.
The routine associates a stream with a file descriptor. File descriptors are obtained from or which open files but do not return pointers
to a FILE structure stream. Streams are necessary input for many of the Section 3s library routines. The type of stream must agree with
the mode of the open file.
When a file is opened for update, both input and output may be done on the resulting stream. However, output may not be directly followed
by input without an intervening or and input may not be directly followed by output without an intervening or an input operation which
encounters end-of-file.
When a file is opened for append with no overwrite (that is when type is "A" or "A+"), it is impossible to overwrite information already in
the file. The routine may be used to reposition the file pointer to any position in the file, but when output is written to the file, the
current file pointer is disregarded. All output is written at the end of the file and causes the file pointer to be repositioned at the
end of the output. If two separate processes open the same file for append, each process may write freely to the file without fear of
destroying output being written by the other. The output from the two processes will be intermixed in the file in the order in which it is
written.
Return Values
The and routines return a NULL pointer on failure.
Environment
SYSTEM_V
When your program is compiled using the System V environment, append with no overwrite is specified by using the "a" or "a+" type string,
and the "A" and "A+" type strings are not allowed.
POSIX
In the POSIX environment, the "a" and "a+" strings, and the "A" and "A+" strings specify append with no overwrite.
See Also
creat(2), dup(2), open(2), pipe(2), fclose(3s), fseek(3s).
fopen(3s)