Most unix commands won't change the input file. Normally you'd redirect the output to another (temporary) file and move it back to the original, but since you're on RHEL you should be able to use sed -i to change the input file inplace.
So I decided to show you my crude way of doing this. Not sure if there is a more elegant solution out there, but here is what I came up with:
The original csv is as follows:
And what I end up with:
Again, fairly crude, but I guess it gets the job done.
Howdy!
I'm trying to automate editing of a configuration file (custom.conf for GDM). I need to find every line between a line that starts with "" and the next line that starts with "", I want to preserve that line, but then delete all the lines in that configuration section and then insert... (3 Replies)
Hi,
I have a situation where I want to replace some occurrences of ".jsp" into ".html" inside a text file.
For Example:
If a pattern found like <a href="http://www.mysite.com/mypage.jsp"> it should be retained.
But if a pattern found like <a href="../mypage.jsp"> it should be changed to... (4 Replies)
Hello,
file1:
not to be changed
not to be changed
<start>
old stuff
old stuff
old stuff
<end>
not to be changed
not to be changed
file2:
new text
new text
desired output: (3 Replies)
can anyone please help me in the below scenario:
File1:
Hello1
Hello1
i want to use sed to replace multiple occurances of Hello1 in file 1 to welcome.
Thanks a ton for the help (9 Replies)
Hello, guys!
"filename" has blocks with three lines each in this fashion:
93909286
#verified
has one bug
10909286
#unverified
pending
10909286
#unverified
pendingThe above example has duplicate blocks, and I have tried using sed to remove just one block... The... (2 Replies)
Hi,
I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Hi,
I want to use sed to replace " /// " with "///" in a text file. However I am getting error messages when I use sed 's/ /// /////g' input.txt > output.txt. How do I go about doing this in sed?
Input:
219518_s_at 0.000189 ELL3 / SERINC4
Output:
219518_s_at 0.000189 ELL3/SERINC4 (5 Replies)
I have a sample text format as given below
<Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text>
<Text Text_ID="10155645315851111_10155645317023456" From="1626711840902323"... (3 Replies)
Good Day Every one
I have a problem finding and replacing text in some large files that will take a long time to manually edit.
Example text file looks like this
#Example Large Text File
unix
linux
dos
squid
bind
dance
bike
car
plane
What im trying to do is to edit all the... (4 Replies)
Hello Everyone,
I have many files like so:
file1.txt
file2.txt
file3.txt
Within each file I have many lines of random text separated by commas like so:
abcAAA,123,defAA,456777,ghiA,789
jklB,101,mnoBBB,11211,pqrB,13111
stuCC,415,vwxCCCC,161,yzaC,718
I am trying to use SED or AWK to... (4 Replies)
Discussion started by: D3U5X
4 Replies
LEARN ABOUT REDHAT
csv
csv(n) CSV processing csv(n)
NAME
csv - Procedures to handle CSV data.
SYNOPSIS
package require Tcl 8.3
package require csv ?0.3?
::csv::join values {sepChar ,}
::csv::joinlist values {sepChar ,}
::csv::read2matrix chan m {sepChar ,} {expand none}
::csv::read2queue chan q {sepChar ,}
::csv::report cmd matrix ?chan?
::csv::split line {sepChar ,}
::csv::split2matrix m line {sepChar ,} {expand none}
::csv::split2queue q line {sepChar ,}
::csv::writematrix m chan {sepChar ,}
::csv::writequeue q chan {sepChar ,}
DESCRIPTION
The csv package provides commands to manipulate information in CSV FORMAT (CSV = Comma Separated Values).
COMMANDS
The following commands are available:
::csv::join values {sepChar ,}
Takes a list of values and returns a string in CSV format containing these values. The separator character can be defined by the
caller, but this is optional. The default is ",".
::csv::joinlist values {sepChar ,}
Takes a list of lists of values and returns a string in CSV format containing these values. The separator character can be defined
by the caller, but this is optional. The default is ",". Each element of the outer list is considered a record, these are separated
by newlines in the result. The elements of each record are formatted as usual (via ::csv::join).
::csv::read2matrix chan m {sepChar ,} {expand none}
A wrapper around ::csv::split2matrix (see below) reading CSV-formatted lines from the specified channel (until EOF) and adding them
to the given matrix. For an explanation of the expand argument see ::csv::split2matrix.
::csv::read2queue chan q {sepChar ,}
A wrapper around ::csv::split2queue (see below) reading CSV-formatted lines from the specified channel (until EOF) and adding them
to the given queue.
::csv::report cmd matrix ?chan?
A report command which can be used by the matrix methods format 2string and format 2chan. For the latter this command delegates the
work to ::csv::writematrix. cmd is expected to be either printmatrix or printmatrix2channel. The channel argument, chan, has to be
present for the latter and must not be present for the first.
::csv::split line {sepChar ,}
converts a line in CSV format into a list of the values contained in the line. The character used to separate the values from each
other can be defined by the caller, via sepChar, but this is optional. The default is ",".
::csv::split2matrix m line {sepChar ,} {expand none}
The same as ::csv::split, but appends the resulting list as a new row to the matrix m, using the method add row. The expansion mode
specified via expand determines how the command handles a matrix with less columns than contained in line. The allowed modes are:
none This is the default mode. In this mode it is the responsibility of the caller to ensure that the matrix has enough columns to
contain the full line. If there are not enough columns the list of values is silently truncated at the end to fit.
empty In this mode the command expands an empty matrix to hold all columns of the specified line, but goes no further. The overall
effect is that the first of a series of lines determines the number of columns in the matrix and all following lines are
truncated to that size, as if mode none was set.
auto In this mode the command expands the matrix as needed to hold all columns contained in line. The overall effect is that after
adding a series of lines the matrix will have enough columns to hold all columns of the longest line encountered so far.
::csv::split2queue q line {sepChar ,}
The same as ::csv::split, but appending the resulting list as a single item to the queue q, using the method put.
::csv::writematrix m chan {sepChar ,}
A wrapper around ::csv::join taking all rows in the matrix m and writing them CSV formatted into the channel chan.
::csv::writequeue q chan {sepChar ,}
A wrapper around ::csv::join taking all items in the queue q (assumes that they are lists) and writing them CSV formatted into the
channel chan.
FORMAT
Each record of a csv file (comma-separated values, as exported e.g. by Excel) is a set of ASCII values separated by ",". For other lan-
guages it may be ";" however, although this is not important for this case (The functions provided here allow any separator character).
If a value contains itself the separator ",", then it (the value) is put between "".
If a value contains ", it is replaced by "".
EXAMPLE
The record
123,"123,521.2","Mary says ""Hello, I am Mary"""
is parsed as follows:
a) 123
b) 123,521.2
c) Mary says "Hello, I am Mary"
SEE ALSO
matrix, queue
KEYWORDS
csv, matrix, queue, package, tcllib
csv 0.3 csv(n)