The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
shell script to remove all lines from a file before a line starting with pattern raksha.s Shell Programming and Scripting 2 03-29-2009 08:13 AM
remove lines in text starting with . (period) Movomito UNIX for Dummies Questions & Answers 11 04-24-2008 11:19 AM
How to remove files starting with - suman_jakkula Shell Programming and Scripting 5 09-14-2006 01:43 AM
Field identification starting from the right jhansrod UNIX for Advanced & Expert Users 3 08-07-2005 02:38 AM
How To Remove files starting with - rahulrathod UNIX for Advanced & Expert Users 2 09-29-2004 04:19 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
sumit207 sumit207 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 10
Remove field starting with * and #

Hi

i have file with data:

abc,*xyz,#abc
123,#123,1234
*123,#123,abc


So i want to remove only fields starting with * and # and i want output as:

abc,,
123,,1234
,,abc

Please suggest something

Thanks
Sumit
  #2 (permalink)  
Old 06-30-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
next time, show what you tried.
Code:

awk -F"," '{
 for(i=1;i<=NF;i++){
    if($i ~ /\#|\*/){
        $i=""    
    }
 }
}1
' OFS="," file
  #3 (permalink)  
Old 07-01-2009
sumit207 sumit207 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 10
code not working

i use dthe abov/e code but it is not working..

The entire row is getting blanks
so my output is 3 blank rows..

Pls suggest sumthing that can take care of this.
  #4 (permalink)  
Old 07-01-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,082
It works fine..

Code:
awk -F"," '{
>  for(i=1;i<=NF;i++){
>     if($i ~ /\#|\*/){
>         $i=""
>     }
>  }
> }1
> ' OFS="," file1
abc,,
123,,1234
,,abc
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0