01-03-2014
Perl Code to change file delimiter (passed as argument) to bar delimiter
Hi,
Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV
I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters.
Any help would be greatly appreciated, thanks
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi experts.
I got a file (500mb max) and need to pivot it (loading into ORCL) and change BLANK delimiter to PIPE |.
Sometimes there are multipel BLANKS (as a particular value may be BLANK, or simply two BLANKS instead of one BLANK).
thanks for your input!
Cheers,
Layout... (3 Replies)
Discussion started by: thomasr
3 Replies
2. Shell Programming and Scripting
Hi
I have a file which have say about 100,000 records..
the records in it look like
Some kind of text 1234567891 abcd February 14, 2008 03:58:54 AM lmnop
This is how it looks.. if u notice there is a 2byte space between each column.. and im planning to replace that with '|' ..
... (11 Replies)
Discussion started by: meghana
11 Replies
3. Shell Programming and Scripting
Hi everybody,
This time I am having one issue in perl.
I have to create comma separated file using the following type of information. The problem is the columns do not have any specific delimiter. So while using split I am getting different value. Some where it is space(S) and some where it is... (9 Replies)
Discussion started by: Amiya Rath
9 Replies
4. Shell Programming and Scripting
Hello I need some help in outputting Fields when the delimiter has changed:
echo "test1,test2 | test3,test4,test5" | awk -F"," '{print $1,"COUNT",$2,$4}'
prints out:
test1 COUNT test2 | test3 test5
But how to change the -F"," to -F"|" delimiter, so that it separates the
fields from $2... (2 Replies)
Discussion started by: sdohn
2 Replies
5. Shell Programming and Scripting
Hi,
I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies
6. UNIX for Dummies Questions & Answers
Hi
I have a file in which delimiter is ';'
However if the delimiter is within "" it is a part of the string and not delimiter.
How to get the fields ? I want to replace the delimiter ';' to '|'.
The file contains data like this :
11111; “2222 2222”; “3333; 3333”; “4444 ""44444”
The file... (2 Replies)
Discussion started by: dashing201
2 Replies
7. Shell Programming and Scripting
Hi all,
I have a number of strings like below:
//mnt/autocor/43°13'(33")W/
and i'm trying to get the numbers in this string, for example
431333
please help
thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies
8. Shell Programming and Scripting
Dear Friends,
I have file as below
1|sdf|rere|sert|trt|rtr
i want to change the delimeter first three columns two fields
expected output
1~sdf~rere|sert|trt|rtr
Plz help (2 Replies)
Discussion started by: i150371485
2 Replies
9. Shell Programming and Scripting
Hi,
I have a No Delimiter variable length text file with following schema -
Column Name Data length
Firstname 5
Lastname 5
age 3
phoneno1 10
phoneno2 10
phoneno3 10
sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies
10. UNIX for Beginners Questions & Answers
I have file 2.txt and I want to change the delimiter form , to :
Not sure what is the problem with below command
cat 2.txt
1,a
2,b
3,d
awk 'BEGIN {FS=",";OFS=":";} {print $0}' 2.txt
Please use CODE tags as required by forum rules! (11 Replies)
Discussion started by: vamsi.valiveti
11 Replies
LEARN ABOUT DEBIAN
text::parsewords
Text::ParseWords(3perl) Perl Programmers Reference Guide Text::ParseWords(3perl)
NAME
Text::ParseWords - parse text into an array of tokens or array of arrays
SYNOPSIS
use Text::ParseWords;
@lists = nested_quotewords($delim, $keep, @lines);
@words = quotewords($delim, $keep, @lines);
@words = shellwords(@lines);
@words = parse_line($delim, $keep, $line);
@words = old_shellwords(@lines); # DEPRECATED!
DESCRIPTION
The &nested_quotewords() and "ewords() functions accept a delimiter (which can be a regular expression) and a list of lines and then
breaks those lines up into a list of words ignoring delimiters that appear inside quotes. "ewords() returns all of the tokens in a
single long list, while &nested_quotewords() returns a list of token lists corresponding to the elements of @lines. &parse_line() does
tokenizing on a single string. The &*quotewords() functions simply call &parse_line(), so if you're only splitting one line you can call
&parse_line() directly and save a function call.
The $keep argument is a boolean flag. If true, then the tokens are split on the specified delimiter, but all other characters (quotes,
backslashes, etc.) are kept in the tokens. If $keep is false then the &*quotewords() functions remove all quotes and backslashes that are
not themselves backslash-escaped or inside of single quotes (i.e., "ewords() tries to interpret these characters just like the Bourne
shell). NB: these semantics are significantly different from the original version of this module shipped with Perl 5.000 through 5.004.
As an additional feature, $keep may be the keyword "delimiters" which causes the functions to preserve the delimiters in each string as
tokens in the token lists, in addition to preserving quote and backslash characters.
&shellwords() is written as a special case of "ewords(), and it does token parsing with whitespace as a delimiter-- similar to most
Unix shells.
EXAMPLES
The sample program:
use Text::ParseWords;
@words = quotewords('s+', 0, q{this is "a test" of quotewords "for you});
$i = 0;
foreach (@words) {
print "$i: <$_>
";
$i++;
}
produces:
0: <this>
1: <is>
2: <a test>
3: <of quotewords>
4: <"for>
5: <you>
demonstrating:
0 a simple word
1 multiple spaces are skipped because of our $delim
2 use of quotes to include a space in a word
3 use of a backslash to include a space in a word
4 use of a backslash to remove the special meaning of a double-quote
5 another simple word (note the lack of effect of the backslashed double-quote)
Replacing "quotewords('s+', 0, q{this is...})" with "shellwords(q{this is...})" is a simpler way to accomplish the same thing.
AUTHORS
Maintainer: Alexandr Ciornii <alexchornyATgmail.com>.
Previous maintainer: Hal Pomeranz <pomeranz@netcom.com>, 1994-1997 (Original author unknown). Much of the code for &parse_line()
(including the primary regexp) from Joerk Behrends <jbehrends@multimediaproduzenten.de>.
Examples section another documentation provided by John Heidemann <johnh@ISI.EDU>
Bug reports, patches, and nagging provided by lots of folks-- thanks everybody! Special thanks to Michael Schwern <schwern@envirolink.org>
for assuring me that a &nested_quotewords() would be useful, and to Jeff Friedl <jfriedl@yahoo-inc.com> for telling me not to worry about
error-checking (sort of-- you had to be there).
perl v5.14.2 2010-12-30 Text::ParseWords(3perl)