So the code supplied:-
If you are not familiar then it probably looks a bit serious. We'll break it down. The vertical bar, known as a pipe mark, joins the output from one operation to the input of the next operation. In this way, you can string a number of processes together. It saves you having to write an output file with each operation to then be read in by the next. All processing happens in memory so saving the I/O effort and time.
From this, you can see you have two statements joined up. The first part reads the file filename and slices it up. The flags on the cut command give the instructions. -d tells cut what the delimiter is (how to count along fields in a record). In our case, we're counting by a " however as this is a special character to we have to mark it as such with an Escape character. The blackslash \ tells the shell not to interpret the " and just pass it as it is into the cut command. If we didn't do this, it would try to interpret the -d flag as open-double-quote, close-double-quote (so nothing), open double-quote, space, filename and then get very confused because it's only expecting a single character. You would probably get an error for ending on an open-double-quote andyway as it will be waiting for the next double-quote to make a valid statement.
The -f2,4 states that we want fields 2 & 4 only.
Slightly annoyingly, this uses the existing delimited of " to separate the fields in the output, so we pass this as input to the tr command with the pipe. The tr command is a character translator. It has two parameters in out case, a double quote and a space. It simply reads all the input then passes it as output converting every occurrence of the double quote into a space.
That is how you generate the output in the format you require.
Does that explain it properly? I've never been a good teacher, so please feel free to complain or ask more questions about it.
Hi folks
I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file.
It all works - apart from the xml and config file format in the new file
with XML files the original XML (that ends up in... (2 Replies)
Hi,
I have a data file with :
01/28/2012,1,1,98995
01/28/2012,1,2,7195
01/29/2012,1,1,98995
01/29/2012,1,2,7195
01/30/2012,1,1,98896
01/30/2012,1,2,7083
01/31/2012,1,1,98896
01/31/2012,1,2,7083
02/01/2012,1,1,98896
02/01/2012,1,2,7083
02/02/2012,1,1,98899
02/02/2012,1,2,7083
I... (1 Reply)
Hi All,
I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for.
My Input data in inputfile.txt
19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Hi,
Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent.
E.g : username empid
------------------------
sri 123
to
username,empid
sri,123
Thanks,
Hema:confused: (2 Replies)
Hi,
i willbe very much grateful to u if u help me out..
if i simply connect pbx machine to printer by serial port RS232 then we find this view:
But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)