I want to select the first column from a daily file called foo.csv. The result is written to file foo.txt. Currently the following script is used for that:
cut -d, -f 1 foo.csv > foo.txt
A typical result would yield :
A12
A45
B11
B67
What needs to happen in addition is that two columns need to be added before writing to file, namely a code (say 'abc') and the current date, such that a typical result would yield :
abc 2008-05-20 A12
abc 2008-05-20 A45
abc 2008-05-20 B11
abc 2008-05-20 B67
How can this be achieved in particular if the date (column 2) should be today's date?
Last edited by figaro; 05-16-2008 at 05:37 PM..
Reason: Simplification of problem
awk is perfectly able to do the job of cut at the same time, so yes, that can be optimized a bit. -F , sets awk's field separator to comma and OFS=FS causes it to use it as the Output Field Separator as well as [Input] Field Separator.
I am having the following problem when executing this script. It currently looks as follows:
The response is "Illegal variable name."
The first few lines of the input file foo.csv look as follows:
SG70,B3B0M92,ANN8132R7036,25-Jun-08
SG68,B3B2J97,ANN8132R6871,25-Jun-08
ST71,B2Q4T68,ANN8132N4540,25-Jun-08
SG67,B3B2J75,ANN8132R6798,24-Jun-08
so it is a list of codes of which the codes in the first column are needed only. Prepended with the code "abc" and the date, the resulting file foo.txt should hold the following data:
Hello,
I am very now to this, hope you can help,
I am looking into editing a file in Solaris, with dinamic collums (lenght varies) and I need 2 things to be made, the fist is to filter the first column and third column from the file bellow file.txt, and create a new file with the 2 filtered... (8 Replies)
I have a file in which I need to add more columns to based on a key in the first file:
File1
key1,abc,123,
key2,def,456,
key3,ghi,789,
File2
key2,zyx,111,qqq,
key3,yuu,222,www,
key1,pui,333,eee,
key4,xxx,999,rrr,
I would like to create the following output:
Output (1 Reply)
Hi Everyone:
My shell script creates multiple csv files (~30) in for loop. I want to compile (or merge) 3rd column from each (all) of these files to another file (in loop). Please help. Thanks. (3 Replies)
Hello,
I have a comma separated flat file. It contains some 20 columns. I want to add two new columns at position 2,3. So that file will have 22 columns. I am providing here sample data with file having 4 columns. Appreciate your help in finding solution for this.
data in input file:... (11 Replies)
Hi All ,
Kindly help me with this soln
awk '{printf "%s %7s \n", $1,$c}' infile
where
value of variable c I am externally giving input
But executing the above command shows all the columns of infile where as I want only 1st column of infile and 2nd column should print value c (8 Replies)
Good afternoon to everyone,
I have some input and output from various widgets that I am trying to get to play nicely together. Basically I would like to stay out of excel and be able to automate the entire process. I have read some posts here about how to use awk, nawk, etc, to do similar... (9 Replies)
Hi everybody,
I've got two simples file1 like:
aaa aaa aaa
bbb bbb bbb
ccc ccc ccc
and file2 like:
111 111 111
222 222 222
333 333 333
I need to:
1) add a line say "new line" as the first line of the file
2)add a column from file2 (say column3) to file1; the new column should... (14 Replies)
Hi
I have a txt file with 4 columns where I need to add 4 empty columns in the middle meaning that I need what is currently column 4 to be column 8 in a new file.
The idea is that I have to use the file as input in a program that reads the data in column 1 and 8, so the content of the other... (8 Replies)
Hi Wise UNIX Crew,
I want to add 3 different columns to the file in which:
1. The first new column pulls in today's date and time
2. Second column one has a '0'
3. Third column has the word 'ANY' going down the column
If my file content is as follows:
"7","a","abc",123"... (1 Reply)