05-31-2009
Quote:
For your first question, it depends on what processing you will do it to the file after converting spaces to a ~ and then when/why do you revert back.
I am working with a csv. which I am building a specified table for another applicaiton.
data1,This has a space
data2, This has a space
data3, This has a space
I am using AWK to split on the space to seperate the two columns however I noticed when I was looping through csv file the loop was seperating each value instead of keeping data1 and This has a space as two elements. I noticed if I replaced the space with a ~ i would then keep the two value relationship while looping. ie.
data1
This~has~a~space
instead of
data1
This
has
a
space
I tried changing the IFS to IFS=, however that was causing an issue for me for the back end processing of the table of keeping track via a counter of when to add a specified # for the table format between every 2 values and then no # at the end of the file. The other issue i noticed was a carriage return at the end of each 2nd value in the csv value which is where I used the TR -d to remove it, which worked.
I am achieving the end result however I'm always looking for a more efficient way. I then would strip the ~ back out and return spaces.
data1
This has a space
#
data2
This has a space
#
data3
This has a space
<no # at end of file>
I am curious with the SED command is that a per line edit comand or does it operate in the same fashion of the tr command of replacing/removing everything in the file at once?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Replace disable_functions in php.ini with value of your choice which may be different on different servers
================================================
-bash-2.05b# grep disable_functions /usr/local/lib/php.ini
disable_functions = 1 2 e weq t ret rye y etyhty rt et e
... (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies
2. Shell Programming and Scripting
Hi
I have 2 files:-
1. List of files which consists of names of some output files.
2. A delimited file; delimted by "|"
I want to replace the value of the $23 (23rd column) in the delimited file with name in the first file. It is always position to position. Meaning first row of the first... (5 Replies)
Discussion started by: pparthiv
5 Replies
3. Shell Programming and Scripting
Please help me with an shell / awk script to achieve following;
File-1:
ABCDW01 12322 23322
BDADW01 22232 24453
EDFAW00 32232 23422
and so on, notice that the first coloumn is a code and the another file contains the real value of each entry in the first colum above but not in a... (4 Replies)
Discussion started by: digipak
4 Replies
4. Shell Programming and Scripting
I want to replace string values from a file to a file
For eg : File1 has 30 lines of string with values, those specific values needs to be changed in file2 and remaining values in file2 should be as it is.
For example:
From file (File1)
cluster.name=secondaryCluster
To replace File... (9 Replies)
Discussion started by: sriram003
9 Replies
5. Shell Programming and Scripting
hi all ,
( perl)
i am trying to replace jst one column in a file for eg
month dayofweek dealar car-name
jan thurs mercedes c300
feb wed lexus is300
all this data is in a master file and i want to replace jan with 1
feb... (5 Replies)
Discussion started by: technoman
5 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I have a tab delimited text file where some lines have the string "NA" in the second column. For these lines, I want to replace NA with the value in the first column, the symbol underscore followed by the value in the fourth column. How do I go about doing that? Thanks!
Input:
1 ... (3 Replies)
Discussion started by: evelibertine
3 Replies
7. Shell Programming and Scripting
Hi,
I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below...
if (start_new_rec=="true"){
exclude_user="false";
user=toupper($6);
match(user, "XXXXX.");
if (RSTART ==2 ) {
... (9 Replies)
Discussion started by: asandy1234
9 Replies
8. Shell Programming and Scripting
please consider the following file, there are repeated blocks of m values, and nested s values within. there are 2 columns (cols 3 and 4)associated with each m,s combination. All s1 rows must get a value of a(col 3 in output), all s2 values must get a value of b(col 3 in output). If s1 and s2 rows... (1 Reply)
Discussion started by: senhia83
1 Replies
9. UNIX for Dummies Questions & Answers
Hello All,
I am having the file as below .I need to replace column 9-12 with some other values. In the below file I need to replace 1509 to 1508 and 1508 to 1507 .Can you please help me in how to do that
Thanks,
Arun
... (10 Replies)
Discussion started by: arunkumar_mca
10 Replies
10. UNIX for Beginners Questions & Answers
Good day guys,
I'm having trouble in creating a logic when it comes to replacing the values inside a file.
I tried using sed command but it just doesn't work the way I want it to be.
Here is what I'm trying to achieve.
If my input file contains the values below.
NAME++GUEST1 ++GUESS2++... (3 Replies)
Discussion started by: asdfghjkl
3 Replies
seek(n) Tcl Built-In Commands seek(n)
__________________________________________________________________________________________________________________________________________________
NAME
seek - Change the access position for an open channel
SYNOPSIS
seek channelId offset ?origin?
_________________________________________________________________
DESCRIPTION
Changes the current access position for channelId.
ChannelId must be an identifier for an open channel such as a Tcl standard channel (stdin, stdout, or stderr), the return value from an
invocation of open or socket, or the result of a channel creation command provided by a Tcl extension.
The offset and origin arguments specify the position at which the next read or write will occur for channelId. Offset must be an integer
(which may be negative) and origin must be one of the following:
start The new access position will be offset bytes from the start of the underlying file or device.
current The new access position will be offset bytes from the current access position; a negative offset moves the access position back-
wards in the underlying file or device.
end The new access position will be offset bytes from the end of the file or device. A negative offset places the access position
before the end of file, and a positive offset places the access position after the end of file.
The origin argument defaults to start.
The command flushes all buffered output for the channel before the command returns, even if the channel is in nonblocking mode. It also
discards any buffered and unread input. This command returns an empty string. An error occurs if this command is applied to channels
whose underlying file or device does not support seeking.
Note that offset values are byte offsets, not character offsets. Both seek and tell operate in terms of bytes, not characters, unlike
read.
EXAMPLES
Read a file twice:
set f [open file.txt]
set data1 [read $f]
seek $f 0
set data2 [read $f]
close $f
# $data1 == $data2 if the file wasn't updated
Read the last 10 bytes from a file:
set f [open file.data]
# This is guaranteed to work with binary data but
# may fail with other encodings...
fconfigure $f -translation binary
seek $f -10 end
set data [read $f 10]
close $f
SEE ALSO
file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3)
KEYWORDS
access position, file, seek
Tcl 8.1 seek(n)