Sponsored Content
Full Discussion: Edit csv file with bash
Top Forums Shell Programming and Scripting Edit csv file with bash Post 302508329 by locoroco on Sunday 27th of March 2011 10:13:49 PM
Old 03-27-2011
Edit csv file with bash

I' trying to use bash to edit a csv file from this format:

"apples","oranges","grapes"
"bread","butter","milk"

To this:

"apples
oranges
grapes"

So that if I would open the csv file in open office,

"apples
oranges
grapes"

Would be in one single cell, and

"bread
butter
millk"

Would also be in one single cell.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies

2. Shell Programming and Scripting

Need to modify csv-file with bash script

Hi Guys, I need to write a script, that exports the "moz_places" table of the "places.sqlite"-file (firefox browser history) into a csv-file. That part works. After the export, my csv looks like this: ... 4429;http://www.sqlite.org/sqlite.html;"Command Line Shell For... (11 Replies)
Discussion started by: Sebi0815
11 Replies

3. Shell Programming and Scripting

Edit csv file

I'm trying to replace the content of cell 4A a csv file with another value. The code itself is successful, but when I try to save the newly changed file content into the old file, it doesn't work: awk -F"," 'NR==4{$1="\"newcontent\","$3}1' test.csv | sed 's/ //g' > test.csv It works only if I... (1 Reply)
Discussion started by: locoroco
1 Replies

4. Shell Programming and Scripting

Convert sql output to csv file via bash tools

hi Can anybody help me with converting such structure into csv file for windows : BAT_ID ID_num CVS_LINE A_SEG SKILL_TO A_CUSTOMER_TYPE --------- ---------- --------------------------------- ---------- ------------------ ----------- 14-MAY-11 777752 ... (4 Replies)
Discussion started by: kvok
4 Replies

5. Shell Programming and Scripting

Read csv file in bash

how to I use IFS to read 2 files (csv) and run the followiung script ./naviseccli -h 1.2.3.4 storagegroup -addhlu -gname $hostname -hlu $hlu_num -alu $alu_num the csv file for $hostname is host1 host2 . . . for hlu and alu its alu,hlu (2 Replies)
Discussion started by: tdubb123
2 Replies

6. Shell Programming and Scripting

Bash script help - removing certain rows from .csv file

Hello Everyone, I am trying to find a way to take a .csv file with 7 columns and a ton of rows (over 600,000) and remove the entire row if the cell in forth column is blank. Just to give you a little background on why I am doing this (just in case there is an easier way), I am pulling... (3 Replies)
Discussion started by: MrTuxor
3 Replies

7. Shell Programming and Scripting

Bash script - add/edit to file and save - sed?

I'm working on a script to execute a number of items. One being, editing particular files to add certain lines. I'm attempting to utilize sed, but, having issues when running from a bash script. Assistance is greatly appreciated. My example: sed -i '14 i\ # add these lines add these lines to... (5 Replies)
Discussion started by: Nvizn
5 Replies

8. UNIX and Linux Applications

GUI to edit and control csv file

Hello, I manage an application with a lot of parameter files under a csv format. I'm looking for a GUI to allow users to edit those files without breaking them. I would like an admin access to define the format of the files (number of columns, format of each column, list of value possible...).... (0 Replies)
Discussion started by: maturix
0 Replies

9. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

10. Shell Programming and Scripting

Bash - make csv file

Hello, im trying to make csv file from a text file that it is the output of pssh command (multiple ssh ) now if i run the command date on all of our servers: i get this output : 14:02:46 192.168.25.230:22 Thu Jul 6 14:02:46 EEST 2017 192.168.70.230: Thu Jul 6 12:02:46 BST 2017 ... (1 Reply)
Discussion started by: batchenr
1 Replies
OB_START(3)								 1							       OB_START(3)

ob_start - Turn on output buffering

SYNOPSIS
bool ob_start NULL PHP_OUTPUT_HANDLER_STDFLAGS ([callable $output_callback], [int $chunk_size], [int $flags]) DESCRIPTION
This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. The contents of this internal buffer may be copied into a string variable using ob_get_contents(3). To output what is stored in the inter- nal buffer, use ob_end_flush(3). Alternatively, ob_end_clean(3) will silently discard the buffer contents. Warning Some web servers (e.g. Apache) change the working directory of a script when calling the callback function. You can change it back by e.g. chdir(dirname($_SERVER['SCRIPT_FILENAME'])) in the callback function. Output buffers are stackable, that is, you may call ob_start(3) while another ob_start(3) is active. Just make sure that you call ob_end_flush(3) the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order. PARAMETERS
o $output_callback - An optional $output_callback function may be specified. This function takes a string as a parameter and should return a string. The function will be called when the output buffer is flushed (sent) or cleaned (with ob_flush(3), ob_clean(3) or similar func- tion) or when the output buffer is flushed to the browser at the end of the request. When $output_callback is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. If the $output_callback is not a callable function, this function will return FALSE. This is the callback signature: string handler (string $buffer, [int $phase]) o $buffer - Contents of the output buffer. o $phase - Bitmask of PHP_OUTPUT_HANDLER_* constants. If $output_callback returns FALSE original input is sent to the browser. The $output_callback parameter may be bypassed by passing a NULL value. ob_end_clean(3), ob_end_flush(3), ob_clean(3), ob_flush(3) and ob_start(3) may not be called from a callback function. If you call them from callback function, the behavior is undefined. If you would like to delete the contents of a buffer, return "" (a null string) from callback function. You can't even call functions using the output buffering functions like print_r($expression, true) or highlight_file($filename, true) from a callback function. Note In PHP 4.0.4, ob_gzhandler(3) was introduced to facilitate sending gz-encoded data to web browsers that support compressed web pages. ob_gzhandler(3) determines what type of content encoding the browser will accept and will return its output accordingly. o $chunk_size - If the optional parameter $chunk_size is passed, the buffer will be flushed after any output call which causes the buffer's length to equal or exceed $chunk_size. The default value 0 means that the output function will only be called when the output buf- fer is closed. Prior to PHP 5.4.0, the value 1 was a special case value that set the chunk size to 4096 bytes. o $flags - The $flags parameter is a bitmask that controls the operations that can be performed on the output buffer. The default is to allow output buffers to be cleaned, flushed and removed, which can be set explicitly via PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUT- PUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE, or PHP_OUTPUT_HANDLER_STDFLAGS as shorthand. Each flag controls access to a set of functions, as described below: +-----------------------------+---------------------------------------------------+ | Constant | | | | | | | Functions | | | | +-----------------------------+---------------------------------------------------+ | | | |PHP_OUTPUT_HANDLER_CLEANABLE | | | | | | | ob_clean(3), ob_end_clean(3), and | | | ob_get_clean(3). | | | | | | | |PHP_OUTPUT_HANDLER_FLUSHABLE | | | | | | | ob_end_flush(3), ob_flush(3), and | | | ob_get_flush(3). | | | | | | | |PHP_OUTPUT_HANDLER_REMOVABLE | | | | | | | ob_end_clean(3), ob_end_flush(3), and | | | ob_get_flush(3). | | | | +-----------------------------+---------------------------------------------------+ RETURN VALUES
Returns TRUE on success or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 7.0.0 | | | | | | | In case ob_start(3) is used inside an output | | | buffer callback, this function will no longer | | | issue an E_ERROR but instead an E_RECOVER- | | | ABLE_ERROR, allowing custom error handlers to | | | catch such errors. | | | | | 5.4.0 | | | | | | | The third parameter of ob_start(3) changed from | | | a boolean parameter called $erase (which, if set | | | to FALSE, would prevent the output buffer from | | | being deleted until the script finished execut- | | | ing) to an integer parameter called $flags. | | | Unfortunately, this results in an API compatibil- | | | ity break for code written prior to PHP 5.4.0 | | | that uses the third parameter. See the flags | | | example for an example of how to handle this with | | | code that needs to be compatible with both. | | | | | 5.4.0 | | | | | | | A chunk size of 1 now results in chunks of 1 | | | byte being sent to the output buffer. | | | | | 4.3.2 | | | | | | | This function was changed to return FALSE in | | | case the passed $output_callback can not be exe- | | | cuted. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 User defined callback function example <?php function callback($buffer) { // replace all the apples with oranges return (str_replace("apples", "oranges", $buffer)); } ob_start("callback"); ?> <html> <body> <p>It's like comparing apples to oranges.</p> </body> </html> <?php ob_end_flush(); ?> The above example will output: <html> <body> <p>It's like comparing oranges to oranges.</p> </body> </html> Example #2 Creating an uneraseable output buffer in a way compatible with both PHP 5.3 and 5.4 <?php if (version_compare(PHP_VERSION, '5.4.0', '>=')) { ob_start(null, 0, PHP_OUTPUT_HANDLER_STDFLAGS ^ PHP_OUTPUT_HANDLER_REMOVABLE); } else { ob_start(null, 0, false); } ?> SEE ALSO
ob_get_contents(3), ob_end_clean(3), ob_end_flush(3), ob_implicit_flush(3), ob_gzhandler(3), ob_iconv_handler(3), mb_output_handler(3), ob_tidyhandler(3). PHP Documentation Group OB_START(3)
All times are GMT -4. The time now is 09:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy