Remove field starting with * and #


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove field starting with * and #
# 1  
Old 06-30-2009
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  
Old 06-30-2009
next time, show what you tried.
Code:
awk -F"," '{
 for(i=1;i<=NF;i++){
    if($i ~ /\#|\*/){
        $i=""    
    }
 }
}1
' OFS="," file

# 3  
Old 07-01-2009
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  
Old 07-01-2009
It works fine..

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to remove lines starting with an ID from all fine in a director

Hi All, I have almost 200 files in a directory I want to remove all lines in each file that is starting with 88002 and 88003. I tried with grep -v and if I plan to do that I need to for all the files individually and it is 200+ files. Any way I can do at single command ... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

2. Shell Programming and Scripting

Select only the lines of a file starting with a field which is matcing a list. awk?

Hello I have a large file1 which has many events like "2014010420" and following lines under each event that start with text . It has this form: 2014010420 num --- --- num .... NTE num num --- num... EFA num num --- num ... LASW num num --- num... (9 Replies)
Discussion started by: phaethon
9 Replies

3. Shell Programming and Scripting

Remove duplicate line starting with a pattern

HI, I have the below input file /* ----------------- cmdsDlyStartFWJ -----------------*/ UNIX_JOB CMDS065J RUN ANY CMDNAME sleep 5 AGENT CMDSHP USER proddata RUN MON,TUE,WED,THU,FRI DELAYSUB 02:00 /* "Triggers daily file watcher jobs" */ ENVAR... (5 Replies)
Discussion started by: varun22486
5 Replies

4. Shell Programming and Scripting

Trying to use sed to remove the value of one field from another field

I'm trying to use sed to remove the value of one field from another field. For example: cat inputfile 123|ABC|Generic_Textjoe@yahoo.com|joe@yahoo.com|DEF 456|GHI|Other_recordjohn@msn.com|john@msn.com|JKL 789|MNO|No_Email_On_This_One|smith@gmail.com|PQR I would like to remove the email... (2 Replies)
Discussion started by: bribri87
2 Replies

5. Shell Programming and Scripting

remove lines starting with

Hi I have an input file... /* ----------------- AGYDLY_Box ----------------- */ insert_job: AGYDLY_Box job_type: b owner: spdrdev permission: gx,wx date_conditions: 1 days_of_week: mo,tu,we,th,fr exclude_calendar: mtg_holidays start_times: "1:00" description: "Process Daily New pools... (2 Replies)
Discussion started by: ramky79
2 Replies

6. Shell Programming and Scripting

How to remove all words starting from a matching word in a line

Hi Guys, I have a file like this: wwwe 1 ioie ewew yyy uuu 88 erehrlk 4 ihoiwhe lkjhassad lkhsad yyy mmm 45 jhash lhasdhs lkhsdkjsn ouiyrshroi oihoihswodnw oiyhewe yyy ggg 77 I want to remove everything after "yyy" and including "yyy" from each line in the file. So I want:... (2 Replies)
Discussion started by: npatwardhan
2 Replies

7. UNIX for Dummies Questions & Answers

remove lines in text starting with . (period)

how can i remove lines from a text file starting with . (a period) (11 Replies)
Discussion started by: Movomito
11 Replies

8. Shell Programming and Scripting

How to remove files starting with -

Hi, Can anyone suggest me how to remove the file whose name starts with "-". Say i have a file by name -out. I want to remove this. I tried escaping -, but didnt work. I work on AIX 5.3 machine. Thanks in advance. Suman (5 Replies)
Discussion started by: suman_jakkula
5 Replies

9. UNIX for Advanced & Expert Users

Field identification starting from the right

Hi all If I have lines in a file as follows :- /ora04/oradata/data1/data1.dbf /ora01/app/product/8.1.6/dbs/F1.Dbf /ora04/oradata/data2.dbf How can I select the last part of the line as my file name. Can I start from the right and define "/" as my delimeter ? Thx J (3 Replies)
Discussion started by: jhansrod
3 Replies

10. UNIX for Advanced & Expert Users

How To Remove files starting with -

In Unix/Linux when u create a file starting with a - e.g.-file then when u try to remove or rename it, it is not possible. e.g. rm -file . when we give this command rm assumes to be its option rather than its argument. Same is the case when this filename is given as an argument to mv or cat and... (2 Replies)
Discussion started by: rahulrathod
2 Replies
Login or Register to Ask a Question