Sponsored Content
Top Forums Shell Programming and Scripting Removing commas within semicolon in a flat file Post 302325837 by ghostdog74 on Tuesday 16th of June 2009 09:25:29 AM
Old 06-16-2009
if you have Python, you can use its csv module
Code:
#!/usr/bin/env python
import csv
filename = "file"
reader = csv.reader(open(filename),delimiter=",")
for row in reader: 
    for n,item in enumerate(row):
        row[n]=row[n].replace(",","")
    print ','.join(row)

output
Code:
# more file
rohan,rahul,kunal,"sw,ati"
rohan,rahul,"kun,al",swati
rohan,"rah,ul",kunal,swati
"ro,han",rahul,kunal,swati

# ./test.py
rohan,rahul,kunal,swati
rohan,rahul,kunal,swati
rohan,rahul,kunal,swati
rohan,rahul,kunal,swati

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

removing commas from text file

Dear all I have a file which looks like this xxxxxxxxxxxxxx,xxx,xxxxxxxxxx xxxxxxxxxxxxxx,xxx,xxxxxxxxxx etc basically 14 characters then a comma, three characters, then a comma then 10 characters. We are uploading this file to our mainframe and they want the commas removed, so it... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

2. HP-UX

Padding zeros after removing commas in file

Hi Gurus, There is a ASCII file in which a comma is used as a seperator for the amount field when the amount exceed seven digits: e.g. 0001300,000. Now, this comma needs to be removed from this field, after padding leading zeros (to maintain the ASCII positions) e.g. 00001300000.... (1 Reply)
Discussion started by: pranag21
1 Replies

3. UNIX for Dummies Questions & Answers

Removing trailer from a flat file!!!

Hi, I get some flat files with trailer which gives the totol records count and i want to remove the trailer from the file. i used the following command it works fine with a single file. cat file_name | grep -v 'Total records:' > file1 mv file file_name But i dont know how to remove the... (12 Replies)
Discussion started by: kumarsaravana_s
12 Replies

4. UNIX for Dummies Questions & Answers

removing semicolon using sed in aix--urgent

hi I have an expression aaabbb; xxx xxxi i need to get the ouput as xxx xxxi i am using sed -e 's/\(*;\)//g' but it is not working..?? can some one suggest.. This is urgent (9 Replies)
Discussion started by: aixjadoo
9 Replies

5. Shell Programming and Scripting

Need help in removing commas

i have the below line as output from a script. I want to delete the string "," and get the output without comma, cat D* | grep "bytes free" | awk '{print $3}' | ????? output: 40,966,189,056 Desired O/P: 40966189056 (1 Reply)
Discussion started by: ali560045
1 Replies

6. Shell Programming and Scripting

Removing commas within semicolon in a flat file

Hi , Im relatively new to unix and have to process a comma serparated flat file . I recieve some of the fields in double quotes and i want to remove it .. INPUT ==== filed1,field2,field3,"fie,ld4" OUTPUT ===== field1,field2,field3,"field4" can anyone tell me how to achieve... (10 Replies)
Discussion started by: r_t_1601
10 Replies

7. Shell Programming and Scripting

Help with removing additional commas in string

Hi Experts, I have below strings hello,hi,,,,,,start date age,code,,,,,61,season I am trying to format this string to hello,hi,start date age,code,61,season Can anyone please help me in achieving this? Kind Regards, RB (3 Replies)
Discussion started by: ramakanth_burra
3 Replies

8. Shell Programming and Scripting

Removing just the trailing commas :-(

Hi all, I haven't needed to do any shell based editing for nearly 20 years, and no amount of searching around has found me a solution to this very simple problem :-( I have a csv file. Some lines have three commas at the end. This means the invoice hasn't been paid. I'd like to use sed / grep... (4 Replies)
Discussion started by: chardyzulu
4 Replies

9. Shell Programming and Scripting

Replace semicolon within double quotes in a file with semicolon delimiter

Hello Team, Could you please help me with the below question? I have a file with the following properties 1) File Delimiter is ; 2) Text columns are within double quotes 3) Numeric columns will not have double quotes 4) File has total 6 columns Please see a sample record from file ... (3 Replies)
Discussion started by: sam99
3 Replies

10. UNIX for Beginners Questions & Answers

Removing commas from CSV file

Hi I'm creating a sh script to generate a csv file. The CSV contains the values from a sql table. The content looks this: a,b,c,c2,c3,,,,,,,,,,,d,e I have some code that can separate the fields using the comma as delimiter, but some values actually contain commas, such as... (2 Replies)
Discussion started by: preema
2 Replies
inotifywatch(1) 					      General Commands Manual						   inotifywatch(1)

NAME
inotifywatch - gather filesystem access statistics using inotify SYNOPSIS
inotifywatch [-hvzrqf] [-e <event> ] [-t <seconds> ] [-a <event> ] [-d <event> ] <file> [ ... ] DESCRIPTION
inotifywatch listens for filesystem events using Linux's inotify(7) interface, then outputs a summary count of the events received on each file or directory. OUTPUT
inotifywatch will output a table on standard out with one column for each type of event and one row for each watched file or directory. The table will show the amount of times each event occurred for each watched file or directory. Output can be sorted by a particular event using the -a or -d options. Some diagnostic information will be output on standard error. OPTIONS
-h, --help Output some helpful usage information. -v, --verbose Output some extra information on standard error during execution. @<file> When watching a directory tree recursively, exclude the specified file from being watched. The file must be specified with a rela- tive or absolute path according to whether a relative or absolute path is given for watched directories. If a specific path is explicitly both included and excluded, it will always be watched. Note: If you need to watch a directory or file whose name starts with @, give the absolute path. --fromfile <file> Read filenames to watch or exclude from a file, one filename per line. If filenames begin with @ they are excluded as described above. If <file> is `-', filenames are read from standard input. Use this option if you need to watch too many files to pass in as command line arguments. -z, --zero Output table rows and columns even if all elements are zero. By default, rows and columns are only output if they contain non-zero elements. Using this option when watching for every event on a lot of files can result in a lot of output! --exclude <pattern> Do not process any events whose filename matches the specified POSIX extended regular expression, case sensitive. --excludei <pattern> Do not process any events whose filename matches the specified POSIX extended regular expression, case insensitive. -r, --recursive Watch all subdirectories of any directories passed as arguments. Watches will be set up recursively to an unlimited depth. Sym- bolic links are not traversed. If new directories are created within watched directories they will automatically be watched. Warning: If you use this option while watching the root directory of a large tree, it may take quite a while until all inotify watches are established, and events will not be received in this time. Also, since one inotify watch will be established per subdi- rectory, it is possible that the maximum amount of inotify watches per user will be reached. The default maximum is 8192; it can be increased by writing to /proc/sys/fs/inotify/max_user_watches. -t <seconds>, --timeout <seconds> Listen only for the specified amount of seconds. If not specified, inotifywatch will gather statistics until receiving an interrupt signal by (for example) pressing CONTROL-C at the console. -e <event>, --event <event> Listen for specific event(s) only. The events which can be listened for are listed in the EVENTS section. This option can be spec- ified more than once. If omitted, all events are listened for. -a <event>, --ascending <event> Sort output ascending by event counts for the specified event. Sortable events include `total' and all the events listed in the EVENTS section except `move' and `close' (you must use `moved_to', `moved_from', `close_write' or `close_nowrite' instead). The default is to sort descending by `total'. -d <event>, --descending <event> Sort output descending by event counts for the specified event. Sortable events include `total' and all the events listed in the EVENTS section except `move' and `close' (you must use `moved_to', `moved_from', `close_write' or `close_nowrite' instead). The default is to sort descending by `total'. EXIT STATUS
0 The program executed successfully. 1 An error occurred in execution of the program. EVENTS
The following events are valid for use with the -e option: access A watched file or a file within a watched directory was read from. modify A watched file or a file within a watched directory was written to. attrib The metadata of a watched file or a file within a watched directory was modified. This includes timestamps, file permissions, extended attributes etc. close_write A watched file or a file within a watched directory was closed, after being opened in writeable mode. This does not necessarily imply the file was written to. close_nowrite A watched file or a file within a watched directory was closed, after being opened in read-only mode. close A watched file or a file within a watched directory was closed, regardless of how it was opened. Note that this is actually imple- mented simply by listening for both close_write and close_nowrite, hence all close events received will be output as one of these, not CLOSE. open A watched file or a file within a watched directory was opened. moved_to A file or directory was moved into a watched directory. This event occurs even if the file is simply moved from and to the same directory. moved_from A file or directory was moved from a watched directory. This event occurs even if the file is simply moved from and to the same directory. move A file or directory was moved from or to a watched directory. Note that this is actually implemented simply by listening for both moved_to and moved_from, hence all close events received will be output as one or both of these, not MOVE. move_self A watched file or directory was moved. After this event, the file or directory is no longer being watched. create A file or directory was created within a watched directory. delete A file or directory within a watched directory was deleted. delete_self A watched file or directory was deleted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened for. unmount The filesystem on which a watched file or directory resides was unmounted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened to. EXAMPLE
Watching the `~/.beagle' directory for 60 seconds: % inotifywatch -v -e access -e modify -t 60 -r ~/.beagle Establishing watches... Setting up watch(es) on /home/rohan/.beagle OK, /home/rohan/.beagle is now being watched. Total of 302 watches. Finished establishing watches, now collecting statistics. Will listen for events for 60 seconds. total access modify filename 1436 1074 362 /home/rohan/.beagle/Indexes/FileSystemIndex/PrimaryIndex/ 1323 1053 270 /home/rohan/.beagle/Indexes/FileSystemIndex/SecondaryIndex/ 303 116 187 /home/rohan/.beagle/Indexes/KMailIndex/PrimaryIndex/ 261 74 187 /home/rohan/.beagle/TextCache/ 206 0 206 /home/rohan/.beagle/Log/ 42 0 42 /home/rohan/.beagle/Indexes/FileSystemIndex/Locks/ 18 6 12 /home/rohan/.beagle/Indexes/FileSystemIndex/ 12 0 12 /home/rohan/.beagle/Indexes/KMailIndex/Locks/ 3 0 3 /home/rohan/.beagle/TextCache/54/ 3 0 3 /home/rohan/.beagle/TextCache/bc/ 3 0 3 /home/rohan/.beagle/TextCache/20/ 3 0 3 /home/rohan/.beagle/TextCache/62/ 2 2 0 /home/rohan/.beagle/Indexes/KMailIndex/SecondaryIndex/ BUGS
There are race conditions in the recursive directory watching code which can cause events to be missed if they occur in a directory immedi- ately after that directory is created. This is probably not fixable. It is assumed the inotify event queue will never overflow. AUTHORS
inotifywatch is written by Rohan McGovern <rohan@mcgovern.id.au>. inotifywatch is part of inotify-tools. The inotify-tools website is located at: http://inotify-tools.sourceforge.net/ SEE ALSO
inotifywait(1), inotify(7) inotifywatch 3.20.1 August 05, 2019 inotifywatch(1)
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy