Get Data From CSV File and put into a txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get Data From CSV File and put into a txt file
# 1  
Old 07-15-2012
Bug Get Data From CSV File and put into a txt file

Hi Guys,

File A

I have File A as CSV Format....


Code:
No	R	SS	MK	Par	value
S	AL	A1	PKL123	Lo12	1
S	AL	A2	PKl123	Lo34	22
S	AL	A3	PkLK234	Lo67	-34
S	AL	A4	PkLK235	Lo09	120
S	AL	A5	PkLK236	Lo76	19
S	AL	A6	PkLK237	Lo44	-17
S	AL	A7	PkLK238	Lo90	2
S	AL	A8	PkLK239	Lo34	-9

I want file B like below......

Code:
S+
C+
S PKL123 Lo12 1
S PKl123 Lo34 22
S PkLK234 Lo67 -34
S PkLK235 Lo09 120
S PkLK236 Lo76 19
S PkLK237 Lo44 -17
S PkLK238 Lo90 2
S PkLK239 Lo34 -9
C-
S-

Thanks in Advance....

Last edited by methyl; 07-15-2012 at 07:44 PM.. Reason: please use code tags. Also corrected spelling and the thread title.
# 2  
Old 07-15-2012
One way (ksh or bash):

Code:
#/usr/bin/env ksh
(
    printf "S+\nC+\n"
    sed '1d; s/\t/ /g' file-A
    printf "C-\nS-\n"
) >file-B

You didn't use code tags, so I'm not 100% sure, but it appears that there were tabs in the input data that you wanted reduced to a single space in the output. If not the sed can be just sed 1d file-A
This User Gave Thanks to agama For This Post:
# 3  
Old 07-15-2012
Quote:
I have File A as CSV Format
(Added Code Tags to Post #1).
The input file is clearly not CSV (Comma Separated Value) because there are no commas. As @agama notes, please state whether the field separator is tab(s) or space characters or a mixture of both characters.
# 4  
Old 07-15-2012
Quote:
Originally Posted by agama
One way (ksh or bash):

Code:
#/usr/bin/env ksh
(
    printf "S+\nC+\n"
    sed '1d; s/\t/ /g' file-A
    printf "C-\nS-\n"
) >file-B

Looks like there's a little bit more to it than that. Fields 2 and 3 need to be cut. I suppose you can pipe cut into sed or just do it in sed itself.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 5  
Old 07-15-2012
Quote:
Originally Posted by alister
Looks like there's a little bit more to it than that. Fields 2 and 3 need to be cut. I suppose you can pipe cut into sed or just do it in sed itself.

Regards,
Alister
Oops, I so missed that; must be getting old! Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert a txt file to a CSV file

Hi , I have a Txt file which consist of 1000's of SOAP request and response and i want the file to be converted to a csv file like column a should have a soap request and column b should have the soap response . can someone assist me in achieving this please ? Thanks (2 Replies)
Discussion started by: kumarm8
2 Replies

2. Shell Programming and Scripting

Extract data from a log file and put it in a file

Hi, I would like to seek your help for a script that will extract data from log file and put it in a file. Sample log file 2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_TH account: 123456789 aiSessionNumber: 660640464 mapName: xxx to yyy errorDesc: Translation Error:ErrorNumber : 993 ... (2 Replies)
Discussion started by: neverwinter112
2 Replies

3. Shell Programming and Scripting

Copy data to CSV file from txt output

Hi Everyone , Below is output from a TL1 , I want just the NE Name: and beside that the Temperature and the voltages in a csv file , Is this possible? > act-user:AB1S2a:ArshadFO:493::**********; AB1S2a 2016-02-07 10:13:24 M 493 COMPLD "ArshadFO:2016-02-07 10-04-55,0" ;... (11 Replies)
Discussion started by: adgjmpt
11 Replies

4. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

5. Shell Programming and Scripting

txt file to CSV

hi.. I have a text file which looks likes this 2258 4569 1239 258 473 i need to convert it into comma seperated format eg:2258,4569,1239,258,437 pls help (8 Replies)
Discussion started by: born
8 Replies

6. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

7. Shell Programming and Scripting

Combine two files and put it in .csv file

Hi Freinds I have two .txt file gem1.txt and gem2.txt, Sample gem1.txt abstract (1.0.0) actionmailer (2.3.5, 2.2.2) actionpack (2.3.5, 2.2.2) activerecord (2.3.5, 2.2.2) activerecord-oracle_enhanced-adapter (1.1.9) activerecord-sqlserver-adapter (2.3.4) activeresource (2.3.5, 2.2.2)... (3 Replies)
Discussion started by: ankit_view24
3 Replies

8. UNIX for Dummies Questions & Answers

Converting txt file to csv file

Hi, Using rsync, I've sent the output to a text file. This is the text file : Pls help me on converting this text file to a csv file. Probably a script or sth to convert the text file to a csv file. (3 Replies)
Discussion started by: anaigini45
3 Replies

9. UNIX for Dummies Questions & Answers

I want some selected data from first file and put into other file in specified format

I have a file with follwing content ---------------------------------- SCHEDULE XXXXXXXXX#JOBCOUNT ON EVERYDAY AT 0000 PRIORITY 50 SCHEDULE XXXXXXXXX#ABCDEFGH ON EVERYDAY AT 0001 PRIORITY 29 SCHEDULE... (5 Replies)
Discussion started by: shreyas
5 Replies

10. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question