How to find the Delimiter?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find the Delimiter?
# 8  
Old 01-06-2011
For find the delimiter, we don't to need analyze the full file. we read the first line of the file is enough. Which string appears maximum time that treaded as the delimter.

The above code @file contains the whole file.
$file[0] -> holds the first line of the file ( Read the array concepts )

$& -> contains the current matching ( Read the perl special variables)
$delim{$&}++ -> increase the count of the matched string ( Read the hashes concept)
This User Gave Thanks to k_manimuthu For This Post:
# 9  
Old 01-06-2011
That helped .. Thank you ..

I tuned the code because i was getting the below error since I am using strict.
<Global symbol "%delim" requires explicit package name at 1.pl>

If I do not use strict then it runs fine.

So I tuned the code as below: Do you think it worksthe same way?



for ($file[0] =~ m{[^\w\n\.]+}g)
{
$delim = $&;
$max++;
if ($max > 0)
{
$destr = $&; # assign the delimiter string to a variable
}
}
# 10  
Old 01-06-2011
Code:
my %delim; # Declare the hashes
for ($file[0] =~ m{[^\w\n\.]+}g) 
{
$delim = $&; 
$max++;
if ($max > 0)
{
$destr = $&; # assign the delimiter string to a variable
}
}

This User Gave Thanks to k_manimuthu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to identify delimiter to find and replace a string with sed?

I need to find and replace a date format in a SQL script with sed. The original lines are like this: ep.begin_date, ep.end_date, ep.facility_code, AND ep.begin_date <= '01-JUL-2019' ep.begin_date, ep.end_date, ep.facility_code, AND ... (15 Replies)
Discussion started by: duke0001
15 Replies

2. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

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

4. Shell Programming and Scripting

how to get everything before the last delimiter?

hi all, i have a string with a number of "/"s as delimiter. and i want everything BEFORE the last delimiter i know to use basename to get everything after the last delimiter. thx a lot! (2 Replies)
Discussion started by: sunnydanniel
2 Replies

5. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

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

6. UNIX for Dummies Questions & Answers

Find delimiter and double quote the field

Hi I have a asterisk (*) delimited file and there are some fields which contain data having asterisk , now i want to double quote the fileds which contain data with asterisk Ex: input file ID*NAME*EMAIL 1*BILL*BILL@AOL.com 2*J*OY*JOY@msn.com in the 2nd record JOY has a asterisk value in... (11 Replies)
Discussion started by: halmstad
11 Replies

7. Shell Programming and Scripting

how to find the nth field value in delimiter file in unix using awk

Hi All, I wanted to find 200th field value in delimiter file using awk.? awk '{print $200}' inputfile I am getting error message :- awk: The field 200 must be in the range 0 to 199. The source line number is 1. The error context is {print >>> $200 <<< } using... (4 Replies)
Discussion started by: Jairaj
4 Replies

8. Shell Programming and Scripting

Find Word within ^A delimiter

I have a file in which the following pattern is there TAG001^A<value>^A I want to find all such values(words) which comes right next to "TAG001^A" and before the next "^A". ^A is the delimiter here. Please help! Note: I think ^A in unix resolves to \001 as delimiter (7 Replies)
Discussion started by: royzlife
7 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

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

10. Shell Programming and Scripting

How to find last delimiter in line?

I am working in a ksh script. I am reading a login, password, and database name from a pre-existing config file. Login and password are simple, I take the value after the first "=" sign, but the dbname has multiple equal signs in it. I have it working by temporarily reading the 23rd field, but... (4 Replies)
Discussion started by: prismtx
4 Replies
Login or Register to Ask a Question