Sponsored Content
Top Forums Shell Programming and Scripting Inserting commas into file at set locations... Post 302565331 by chedlee88-1 on Monday 17th of October 2011 02:52:40 PM
Old 10-17-2011
Quote:
Originally Posted by Astrocloud
Hey everyone.

What would be the best method to insert commas (or comma-quotes) into a file at set locations.

Every line in the file looks like this:
Code:
 1234567890123456 123456BIGAUDIODYNAMITE33      123.12  123456  12345678901234MARK E WILLIAMS           123456

The comma's should appear at: 11,17,18,20,22,24,40,45,54,62,78,101,103,105,107

Hence the line above should look like (with comma quotes)

Code:
" 1234567890","123456"," ","12","34","56","BIGAUDIODYNAMITE","33   ","   123.12", "  123456","  12345678901234","MARK E WILLIAMS           ","12","34","56

Someone surely has a script that does this...

Thanks in Advance

#!/bin/sh

while read line
do
F1=`echo $line | cut -c1-7`
F2=`echo $line | cut -c8-17`
F3=`echo $line | cut -c17-27`
echo "$F1,$F2,$F3"
done
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting commas and replacing backslashes with commas

Hi, Newbie here. I have a file that consists of data that I want to convert to a csv file. For example: Jul 20 2008 1111 / visit home / BlackBerry8830/4.2.2 Profile/MIDP-2.0 Configuration/CLOC-1.1 VendorID/105 Jul 21 2008 22222 / add friend / BlackBerry8830/4.2.2 Profile/MIDP-2.0... (3 Replies)
Discussion started by: kangaroo
3 Replies

2. Solaris

file locations...

Hi Guys, There was a post that I saw here a while ago regarding file system layout and what to put where, which I am unable to find now.. A user here posted a man page that list what each partition should have in it and what it is used for and were you should install custom packages. ie:... (1 Reply)
Discussion started by: Tornado
1 Replies

3. Shell Programming and Scripting

Sending a file to 24 Server locations parallely

Hi All, I have to send a processed file to 24 different server locations. I feel, if this job can be done parallel in the background - Time will come down. I found the script to FTP the file for a single server location through past Unix posts as below: #!/usr/bin/ksh ftp -v -n... (16 Replies)
Discussion started by: vsmeruga
16 Replies

4. UNIX for Advanced & Expert Users

Insert Delimiter at fixed locations in a flat file

Hi Can somebody help me with solution for this PLEASE? I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width. For Example Here is the file { kkjhdhal sdfewss sdtereetyw... (7 Replies)
Discussion started by: jd_mca
7 Replies

5. Shell Programming and Scripting

Program to insert Delimiters at fixed locations in a file, Can you please Debug it for me??

Can someone please help?I have a file - fixed.txt----------------------------AABBBBCCCCCCDDDEEFFFFGGGGGGHHHIIJJJJKKKKKKLLL----------------------------To insert delimiters at fixed lengths of 2, 4, 6, 3, I created a file text1.txt as-------------------2463----------------------and trying to execute... (10 Replies)
Discussion started by: jd_mca
10 Replies

6. Shell Programming and Scripting

Remove leading commas in the file

Hi , I have a file with below records 965382,10310858,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 767010,10217614,3,10217616,10217622,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,... (4 Replies)
Discussion started by: vputtas@gmail.c
4 Replies

7. UNIX for Dummies Questions & Answers

Edit locations in a file

Hi , I have a file which looks like this source1 LEN predictive 392879 394347 0.955489 + . Name=sa000003.1;ID=sa000003;Alias=sa121751.1; source1 LEN descriptive_1 391082 392878 . . . Parent=sa000003.1;supp_id=.1805.1; ... (3 Replies)
Discussion started by: siya@
3 Replies

8. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

9. UNIX for Beginners Questions & Answers

Removing commas from CSV file

Hi I'm creating a sh script to generate a csv file. The CSV contains the values from a sql table. The content looks this: a,b,c,c2,c3,,,,,,,,,,,d,e I have some code that can separate the fields using the comma as delimiter, but some values actually contain commas, such as... (2 Replies)
Discussion started by: preema
2 Replies
whereami(8)						      System Manager's Manual						       whereami(8)

NAME
whereami -- non-interatively ascertain the location of the computer and reconfigure the system appropriately. SYNOPSIS
whereami [--debug ] [--scriptdebug ] [--syslog ] [--noactions ] [--nolocking ] [--mapping ] [--basedir directory ] [--statedir directory ] [--from location_list ] [--run_from calling_program_tag ] [location_list] DESCRIPTION
`whereami' provides a configurable and extensible framework for automatic location-detection and reconfiguration of computers, typically laptops. Detection Detection is handled through the use of various network and hardware probing tools. These tools have been wrapped in small shell scripts to interface them to whereami, but the end-user with different requirements may wish to extend these in some situations. whereami processes the file /etc/whereami/detect.conf performing the tests specified in there in order to decide which location the com- puter is currently located at. For full detail on the discovery process, you should read the detect.conf (5) manpage. Configuration Configuration is handled through standard shell scripting. A variety of small utility scripts are provided and the author is always will- ing to accept more. The file /etc/whereami/whereami.conf is parsed and a script built containing the actions specified there which are associated with the locations found during the detection phase. Actions may be configured for when leaving, remaining, or arriving at a location. Once the script has been built, it is run to effect the necessary changes to the system configuration. OPTIONS
This program follows the modern command-line syntax preceding each option with a double dash (`--'). Short form options are also avail- able, but are not documented (RTFC :-) --debug Run in debugging mode. A verbose output is provided and the resulting script is output to the screen and not executed. --scriptdebug Run in script debugging mode. Each script supplied with `whereami' will `set -o xtrace' if the environment variable `DEBUGWHERE- AMI' is set to non-blank. This parameter will set that variable. The script which is built by whereami will also respond to the environment variable. --syslog Output some logging information to syslog. The 'user' facility is used for this, and it provides an insight into which locations whereami has chosen, and why. In combination with --scriptdebug above, this can be very useful for debugging your configuration. Also note that the default installation turns this on for apm and init actions. --noactions Just do the detection and print the location name. Don't build and run the script from whereami.conf. You might do this if you wanted to use whereami's detection, but use something else for configuration. Perhaps you could achieve the same end with a very simple whereami.conf, but there should always be two ways to do anything :-). --nolocking whereami won't normally let two copies of whereami run at the same time. Use this option if you can come up with a scenario where you should allow this to happen! --mapping This will persuade whereami to do only the detection stage, and output a list of the detected locations, suitable for use as a mapping script with ifupdown. --hint locations Provides some hints to the detection process. The locations set by this parameter (a comma-delimited list) may be referenced by rules in your detect.conf. --basedir directory Specifies the base directory which will contain both the detect.conf and whereami.conf. The default is `/etc/whereami' which should be right for normal use. --statedir directory Specifies the state directory in which whereami will write files indicating the current and previous locations (iam , iwas) and the script which is run for this environment (whereiam.sh). --from location_list Overrides whereami's knowledge of where you have come from. The location_list will be a comma-separated list of the locations which you are leaving. Normally `whereami' maintains a history of locations, so that it knows where you have come from (and what might consequently have to be de-configured) as well as knowing that your location has changed. --run_from calling_program_tag This provides a mechanism for calling software, such as init scripts, pcmcia startup or apm events, to pass some of that source information to whereami, where it is promptly ignored, at present. I have a possibly misguided idea that this might be useful somehow, but I can't think of any application of it at this point! location_list Overrides whereami's testing of where you are. The location_list will be a comma-separated list of the locations which you are now at. You might use this if you wished to bypass the detection phase, using some other package to handle that. SEE ALSO
detect.conf (5), whereami.conf (5) There is some further documentation in HTML available in /usr/share/doc/whereami/manual FILES
/etc/whereami/detect.conf Defines the process of detection. /etc/whereami/whereami.conf Defines the actions performed as a result of entering, leaving, or remaining within a particular location. KNOWN BUGS
This man page only documents the current perl version of whereami. For backward compatibility with people's setups, it is possible to con- figure your system to run the older shell-script, which is currently undocumented. If you wish to switch from the shell script to the new perl program you will need to create an appropriate `detect.conf' file to define your location detection parameters. Your existing whereami.conf file should be compatible with this version. Once you have created a detect.conf file in /etc/whereami you should run `dpkg-reconfigure whereami' and respond to the questions. AUTHOR
This manual page was written by Andrew McMillan <debian@mcmillan.net.nz> for the Debian GNU/Linux system (but may be used by others). Per- mission is granted to copy, distribute and/or modify this document under the terms of the GPL version 2. whereami(8)
All times are GMT -4. The time now is 02:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy