Hi,
i am posting this after not finding proper solution in any other discussion threads
I have a text data file with the first row as the column header names.
The file can be comma, tab, space, pipeline, .... delimited
Example of a pipeline delimited:
file1.txt
If i call a script say script1.sh and pass the input data delimiter, output delimiter, ColC and ColF as parameters,
it should only display data for those two columns and in the desired format
Note that we should be able to pass any number of column names to the script.
For our example i am using only 2 columns
I don't want to pass column position as parameter because the order of columns can change in the next data file
Here "|" means it's the delimiter for the input data, "," is the delimiter to be used for output, the remaining parameters are the column names
The output should be:
It's okay not to print the column header in the output
Any help on how to write script1.sh is greatly appreciated
Thanks,
-srinivas y.
Moderator's Comments:
Please use code tags when posting data and code samples!
Last edited by vgersh99; 01-06-2012 at 04:00 PM..
Reason: code tags, please!
ctsgnb, your example has hardcoded column position
I want to able to pass column name as it appears in the column header as parameter
'colD' need not be in the 4position next time.
I think i should have chosen better column names to avoid confusion
---------- Post updated at 02:19 PM ---------- Previous update was at 02:15 PM ----------
vgersh99, thanks but the provided link has an example to search only one column and for a space delimited file
I would like to pass multiple and provide the input and output delimiter
vgersh99, thanks but the provided link has an example to search only one column and for a space delimited file
I would like to pass multiple and provide the input and output delimiter
Thanks
You can take the quoted thread as a 'starter/skeleton' and adjust for any additional functionality.
Not sure the scripting language is adapted fo doing such things. Of course it is still possible but more tedious than a select into a Database.
Put your data into a database then
there is also a bunch of formatting option available in SQL,SQL+,Pl/Sql so that you can make the rendering fit with your expectations.
Hi,
I am trying to split the following output into two columns, where each column has Source: Destination:
OUTPUT TO FILTER
$ tshark -r Capture_without_mtr.pcap -V | awk '/ (Source|Destination): /' | more
Source: x.x.x.x
Destination: x.x.x.x
Source:... (2 Replies)
I want to split this with every 5 or 50 depend on how much data the file will have. And remove the comma on the end
Source file will have
001,0002,0003,004,005,0006,0007,007A,007B,007C,007E,007F,008A,008C
Need Output from every 5 tab and remove the comma from end of each row
... (4 Replies)
Hi Experts,
Please bear with me, i need help
I am learning AWk and stuck up in one issue.
First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique.
Second point : For... (1 Reply)
HI,
My Input file data is
dn:adcfgeneral
id:13343
Name:xxxxxx
Password:iutyerwuitywue wpuwt
tuiytruityrutyrwtyrwp
dn:cdferwjyyyy
id:3875
Name:yyyy
Password :hgfdsjkfhdsfkdlshf
dshfkldshfdklsfh
interset:uiuiufj
My output should be
... (6 Replies)
Hello Members,
I have a csv file in the format below. Need help with awk statement to break nth column into 3 separate columns and export the changes to new file.
input file --> file.csv
cat file.csv|less
"product/fruit/mango","location/asia/india","type/alphonso"
need output in... (2 Replies)
a,b,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii
a thru ii are digits and strings....
The awk needed....if coloumn 9 == i (coloumn 9 is string ), output the sum of x's(coloumn 22 ) in all records and sum of y's (coloumn 23 ) in all records in a file (records.txt).... (6 Replies)
I have some data that is something like this?
item: onhand counted location
ITEM0001 1 0 a1
ITEM0001 0 1 a2
ITEM0002 5 0 b5
ITEM0002 0 6 c1
I want to sum up... (6 Replies)
Hi -
I'm new to the awk programming language. I'm trying to print a single column of data to several columns, and I found an article on iTWorld.com (ITworld.com - Printing in columns). It looks like the mkCols2 script is very close to what I need to do, but it looks like the end of the code... (2 Replies)
Hi All,
I have a table with 10 columns. Some columns(2nd,4th,5th,7th,8th and 10th) are Not Null columns. I'll get a tab-delimited file and want to check col by col and generate seperate error code for each col eg:102 if 2nd col value is NULL and 104 if 4th col value is NULL so on... I am a... (7 Replies)