Sponsored Content
Top Forums Shell Programming and Scripting Awk to convert a text file to CSV file with some string manipulation Post 302687915 by FreddyDaKing on Friday 17th of August 2012 08:21:35 AM
Old 08-17-2012
Awk to convert a text file to CSV file with some string manipulation

Hi ,

I have a simple text file with contents as below:

Code:
12345678900    971,76    4234560890
22345678900   5971,72    5234560990
32345678900     71,12    6234560190

the new csv-file should be like:

Code:
Column1;Column2;Column3;Column4;Column5
123456;78900;971,76;423456;0890
223456;78900;5971,72;523456;0990
323456;78900;71,12;623456;0190

The requirements are:
  • Column1 contains first six characters of first number in text file
  • Column2 contains last five characters of first number in text file
  • Column3 contains complete semicolon separated number of text file
  • Column4 contains first six characters of last number in text file
  • Column4 contains last four characters of last number in text file

Unfortunately I'm some kind of newbie in awk. I've tried writing some scripts by myself, but not with to much success.

Any help&hints would be appreciated.

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk to convert a flat file to CSV file

Hi , I have a file with contents as below: Contract Cancellation Report UARCNCL LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY ========= ======= ==== ==== ==== ========= ==== ==== 8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN 8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies

2. Programming

convert text file to csv

hi all, i have a select query that gives me the output in the following way... SYSTYPE -------------------------------------------------------------------------------- Success Failures Total RFT ---------- ---------- ---------- ---------- TYP 1 0 ... (3 Replies)
Discussion started by: sais
3 Replies

3. UNIX for Dummies Questions & Answers

Convert entries in a text file to values in a string

How to convert entries in a text file to values in a string? ex: I have a text file list.txt with following entries : aaaa bbbb cccc dddd I want to move the values in the list.txt file to an array (names) need a small script to do that? Thanks for your help in advance (3 Replies)
Discussion started by: kukretiabhi13
3 Replies

4. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
2 Replies

5. Programming

String Manipulation in a text file

Hi I have a requirement to write a script but not sure which is the best way to approach this I have not worked in sed but I'm aware that its robust for file extraction requirements I have a scripting task. I already developed the code in perl but the script is taking almost 2 mins for... (5 Replies)
Discussion started by: John Trevor
5 Replies

6. Shell Programming and Scripting

Trying extract from text file and convert csv

I want to extract IP address, system ID and engine IDs of this file ( marked in red) and put in a csv. E.g. 1.1.1.1, SYSTEMID, 000012345678981123548912 I get these file by running an expect script from solaris. Here is the text file output of my expect script. working on 1.1.1.1 SNMP... (5 Replies)
Discussion started by: pbshillong
5 Replies

7. Shell Programming and Scripting

How to convert excel file to csv file or text file?

Hi all, I need to find a way to convert excel file into csv or a text file in linux command. The reason is I have hundreds of files to convert. Another complication is the I need to delete the first 5 lines of the excel file before conversion. so for instance input.xls description of... (6 Replies)
Discussion started by: johnkim0806
6 Replies

8. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

9. Shell Programming and Scripting

Need to Preprocess a text file and convert into csv

Hello, I was working with Machine learning and would like to apply my regression algorithms on binary classification datasets. So I came across this adult dataset, LIBSVM Data: Classification (Binary Class) It is a binary dataset, features have values only 1 and 0. and I wanted to... (4 Replies)
Discussion started by: ajayram
4 Replies

10. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies
XmTextFieldGetSubstringWcs(3X)											    XmTextFieldGetSubstringWcs(3X)

NAME
XmTextFieldGetSubstringWcs - A TextField function that retrieves a portion of a wide character internal text buffer SYNOPSIS
#include <Xm/TextF.h> int XmTextFieldGetSubstringWcs (widget, start, num_chars, buffer_size, buffer) Widget widget; XmTextPosition start; int num_chars; int buffer_size; wchar_t *buffer; DESCRIPTION
XmTextFieldGetSubstringWcs retrieves a copy of a portion of the internal text buffer of a TextField widget that is stored in a wide charac- ter format. The function copies a specified number of characters from a given start position in the internal text buffer into a buffer provided by the application. A NULL terminator is placed at the end of the copied data. Specifies the TextField widget ID. Specifies the beginning character position from which the data will be retrieved. This is an integer number of characters from the beginning of the text buffer. The first character position is 0. Specifies the number of wchar_t characters to be copied into the provided buffer. Specifies the size of the supplied buffer as a number of wchar_t storage locations. The minimum size is num_chars + 1. Specifies the wide character buffer into which the internal text buffer will be copied. For a complete definition of TextField and its associated resources, see XmTextField(3X). RETURN VALUE
The function was successful. The function failed because it was unable to copy the specified number of characters into the buffer pro- vided. The buffer size may be insufficient. The contents of buffer are undefined. The requested number of characters extended beyond the internal buffer. The function copied characters to the end of the buffer and terminated the string with a NULL terminator; fewer than num_chars characters were copied. SEE ALSO
XmTextField(3X), XmTextFieldGetSubstring(3X) XmTextFieldGetSubstringWcs(3X)
All times are GMT -4. The time now is 07:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy