![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UNIX newbie NEWBIE question! | Hanamachi | UNIX for Dummies Questions & Answers | 4 | 03-28-2009 04:10 PM |
| newbie to unix programming in C, needed a few simple prgs on these functions! | wrapster | High Level Programming | 1 | 06-22-2008 01:12 PM |
| Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix | mailsukumar | Shell Programming and Scripting | 0 | 05-26-2008 08:12 AM |
| urgent help needed on HP 9000 rp3410 server for a newbie | bnaravinda | HP-UX | 4 | 08-09-2007 06:54 AM |
| Newbie help needed connecting to Internet | FattyLumpkin | UNIX Desktop for Dummies Questions & Answers | 3 | 07-05-2002 06:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
Can i get some help from any of you guyz on writing Unix script. my requirement is like reading a csv file, finding a specific pattern in the lines and repalce the string with new string and write it to another file. My file is file ABC123.dat Col1,Col2,Col3 102628,AB10 0,21 102628,AB10 1,21 102628,AB10 2,21 102628,AB23 5,21 102628,AB35 9,21 102628,AB53 8AA,21 102628,AB53 8AB,21 102628,AB53 8AD,21 102628,AB53 8AE,21 102628,AB53 8AG,21 102636,AB54 0,21 102636,AB54 1,21 102636,AB54 2,21 102636,AB54 3,21 102636,AB54 4,21 102636,AB54 5,21 102636,AB54 6,21 102636,AB54 7A,21 102636,AB54 7B,21 102636,AB54 7D,21 102636,AB54 7E,21 888888,A99 9,21 and i have written a small script which finds the the pattern and prints the line numbers too but i am unable to write to another file.... file=/export/home/prashant/ABC123.dat String1="[,][A-Z][A-Z][0-9][0-9][ ][0-9][,]" String2="[,][A-Z][0-9][0-9][ ][0-9][,]" String3="[,][0][,]" # Replacement for the string 1 & 2 if found the pattern in the file. if [ -f "file" ]; then echo "File $file does not exist." exit 1 fi cmd=$`(grep -c "[$String1|$String2]" $file)` line=$(grep -n "$String1" $file) line1=$(grep -n "$String2" $file) if [ "$cmd" != "0" ]; then echo "the String exists what you are expecting in the Line Number" echo "$line" echo "$line1" else echo "Word does not exist." fi out put is something like this .... the String exists what you are expecting in the Line Number 2:102628,AB10 0,85 3:102628,AB10 1,85 4:102628,AB10 2,85 5:102628,AB23 5,85 6:102628,AB35 9,85 12:102636,AB54 0,85 13:102636,AB54 1,85 14:102636,AB54 2,85 15:102636,AB54 3,85 16:102636,AB54 4,85 17:102636,AB54 5,85 18:102636,AB54 6,85 23:888888,A99 9,85 but i am unable to replace the string1 & string2 after finding in the file with the string3 variable to another file ..... thanks prashant |
|
||||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|