Sponsored Content
Top Forums Shell Programming and Scripting Issue with Pattern Matching in Unix Post 302347749 by coding-school on Wednesday 26th of August 2009 10:18:25 AM
Old 08-26-2009
How about gawk? :)

Code:
% gawk -F',' ' {

if(NF==5) { if($3 ~ /^0/) { $3 = "\"" $3 "\"" } print $0 }
else {
    sno=$1

    if($3 !~ /^[0-9]*$/)  {

        name="\"" $2 "," $3 "\""; zip=$4;

        if($(NF-1) !~ /^[0-9]*$/)  {

             care_of="\"" $(NF-1) "," $(NF) "\""; rank=$(NF-2);

        } else { care_of=$6;rank=$5; }

    } else {

         if($3 ~ /^0/) { $3 = "\"" $3 "\"" }
         name=$2; zip=$3;
         if($(NF-1) !~ /^[0-9]*$/)  { care_of="\"" $(NF-1) "," $(NF) "\""; rank=$(NF-2); } else { care_of=$5;rank=$4; }
    }
    if(zip ~ /^0/) { zip = "\"" zip "\"" }
    print sno "," name "," zip "," rank "," care_of
}

} ' inputFile.csv > outputFile.csv

% cat *csv
SNO,NAME,ZIPCODE,RANK,CARE_OF
1,Robert Ken,74538,12,RICHARD JOHNSON, P.C
2,Sam Mik,07564,13,% R.S MIKE, V.K.S
3,Kim, Ed,12345,14,@90 KMS, %TK
SNO,NAME,ZIPCODE,RANK,CARE_OF
1,Robert Ken,74538,12,"RICHARD JOHNSON, P.C"
2,Sam Mik,"07564",13,"% R.S MIKE, V.K.S"
3,"Kim, Ed",12345,14,"@90 KMS, %TK"

Cheers,

coding-school
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern Matching in UNIX

Hello, I have a pattern like "XXXXXX XXXXXX" which i need to make search in a input file and Replace the matched pattern to a another pattern. This is the code i tried .. #!/usr/bin/perl print "Enter a File name :"; chomp ($file = <STDIN>); print "\n Searching file :"; if (system ("ls... (2 Replies)
Discussion started by: maxmave
2 Replies

2. Shell Programming and Scripting

Pattern Matching problem in UNIX

Hello All, I need help I have a problem in searching the pattern in a file let us say the file contains the below lines line 1 USING *'/FILE/FOLDER/RETURN') ................. ................. line 4 USING *'/FILE/FOLDER/6kdat1') line 5 USING... (2 Replies)
Discussion started by: maxmave
2 Replies

3. UNIX for Advanced & Expert Users

pattern matching in unix

Task is to identify files like code.1 , code.23 and so on ... (the files which are ending with a number) but it should not match files like code.123abc. So the search will normally search for files with "code." and at the end we should extract for the correct match. Now I have to remove these files... (6 Replies)
Discussion started by: diwakar_reddy
6 Replies

4. Shell Programming and Scripting

Perl Pattern Matching:Unix Vs. Window (Is it OS dependent??)

Hi All, Below I am discussing the problem I am facing while using pattern matching in Unix & Window. Plz hv a look into it. ================ my $s="UPDATE A SET s="klkkk' ;" ; if ( $s =~ m/^*UPDATE+/i ) { print $s; } else { print "no match";} =================== Both should... (6 Replies)
Discussion started by: Niroj
6 Replies

5. Shell Programming and Scripting

pattern matching on any special character in Unix

Hi, I have field in a file which would come with any special character, how do i check that field? Eg: @123TYtaasa>>>/ 131dfetr_~2 In the above example, how do I add pattern for any special character on the keyboard. Thanks (3 Replies)
Discussion started by: techmoris
3 Replies

6. Shell Programming and Scripting

Pattern matching in Perl issue

Hello all, I have written a perl script which searched for a file in a folder, and return the value found or not found. The file that we are getting is a weekly file and everyweek, the date changes. So for this i have written a file pattern matching script, but i am not getting the... (4 Replies)
Discussion started by: msrahman
4 Replies

7. Shell Programming and Scripting

awk pattern matching and shell issue.

Please help me in this issue. I am unable to get the job,seems the awk not browsing the files. Please find my tries below. I have attached two files : 1.tobesearched.txt - a glimpse of a huge log file. 2.searchstring.txt - searching keys. these are the two scripts i tried writing: ... (7 Replies)
Discussion started by: deboprio
7 Replies

8. Shell Programming and Scripting

issue with pattern matching

i have 2 strings with values below which are read from a file 1 ---> end 2 ---> string(1)newline="\n"; which need to be compared inside an if block as below if \\n\"\;" ] then echo "pattern match" fi but the above code is not working (1 Reply)
Discussion started by: cvsanthosh
1 Replies

9. Shell Programming and Scripting

awk script issue redirecting to multiple files after matching pattern

Hi All I am having one awk and sed requirement for the below problem. I tried multiple options in my sed or awk and right output is not coming out. Problem Description ############################################################### I am having a big file say file having repeated... (4 Replies)
Discussion started by: kshitij
4 Replies

10. UNIX for Beginners Questions & Answers

Binary pattern matching in UNIX

I think what I'm trying to do is pretty straightforward but I just can't find a way to do it. I'm trying to run a double pattern match in a three column file. If the first two columns match, I need to output the third. So in the file AAA BBB 1 BBC CCC 5 CCC DDD 7 DDD EEE 12 If the... (4 Replies)
Discussion started by: matthewndavies1
4 Replies
zipnote(1)						      General Commands Manual							zipnote(1)

NAME
zipsplit - split a zipfile into smaller zipfiles SYNOPSIS
zipsplit [-t] [-i] [-p] [-s] [-n size] [-r room] [-b path] [-h] [-v] [-L] zipfile ARGUMENTS
zipfile Zipfile to split. OPTIONS
-t Report how many files it will take, but don't make them. -i Make index (zipsplit.idx) and count its size against first zip file. -n size Make zip files no larger than "size" (default = 36000). -r room Leave room for "room" bytes on the first disk (default = 0). -b path Use path for the output zip files. -p Pause between output zip files. -s Do a sequential split even if it takes more zip files. -h Show a short help. -v Show version information. -L Show software license. DESCRIPTION
zipsplit reads a zipfile and splits it into smaller zipfiles. EXAMPLES
To be filled in. BUGS
Does not yet support large (> 2 GB) or split archives. SEE ALSO
zip(1), unzip(1) AUTHOR
Info-ZIP v3.0 of 8 May 2008 zipnote(1)
All times are GMT -4. The time now is 04:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy