Sponsored Content
Top Forums Shell Programming and Scripting insert data into specific lines of a CSV Post 302448642 by Corona688 on Thursday 26th of August 2010 01:38:08 PM
Old 08-26-2010
I'm guessing the file is tab-separated? This should replace the fields you wanted all with the same serial, part, and tech...
Code:
#!/bin/bash

# Assume input for 'read' is tab-seperated
IFS=$'\t'

while read -a ARRAY
do
        # Print and skip comment lines
        if [[ "${ARRAY[0]:0:2}" == "//" ]]
        then
                echo "${ARRAY[*]}"
                continue
        fi

        # Modify different fields based on the type given
        if [[ "${ARRAY[1]}" == "H" ]]
        then
                ARRAY[7]="USA075WB"
                ARRAY[3]="W8738625Z5V"
        elif [[ "${ARRAY[1]}" == "D" ]]
        then
                ARRAY[3]="922-9592"
        fi

        # Write the entire array back out, still tab-seperated
        echo "${ARRAY[*]}"
done < file.in > file.out

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert lines at specific location in file

Hi There I have this file that I would like to add entries to, however, there is a "}" as the last line that I need to keep. Basically i would like to know how I can write a script that will add new lines at the second to last line position (ie always add new line above the close bracket) ... (17 Replies)
Discussion started by: hcclnoodles
17 Replies

2. Shell Programming and Scripting

Insert 2 lines in a file at a specific location

Hi, I need to insert two new lines in a file: The file: "..... ...... ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`" .... .... " I need to add the lines: LD_LIBRARY_PATH='$LD_LIBRARY_PATH:$APACHE_HOME/modules' DOWNLOADMODULE_CONF_PATHNAME='$APACHE_HOME/conf/DWLModule.cfg' right... (2 Replies)
Discussion started by: potro
2 Replies

3. Homework & Coursework Questions

Displaying specific lines from a CSV file

1. The problem statement, all variables and given/known data: Display from a csv file, birthdays that occur today. If there are no birthdays today, the next one in the year. 2. Relevant commands, code, scripts, algorithms: The csv file is ordered from older to younger (ie. the most recent... (8 Replies)
Discussion started by: Adzi
8 Replies

4. Shell Programming and Scripting

Can sed be used to insert data at specific column?

I'm trying to use sed to insert data at a specific column, let's say my data looks like this: 0553 1828 0552 1829 0550 1829 0549 1830 0548 1831 what I want is this: timein 0553 timeout 1828 timein 0552 timeout 1829 timein 0550 timeout 1829 timein 0549 timeout 1830 timein 0548... (5 Replies)
Discussion started by: mswartz
5 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

7. Shell Programming and Scripting

Insert text line to specific location CSV

In Perl. ***edited question below*** Hey all, I am teaching myself some simple CSV file manipulation and have become a little stuck. Say I have the following layout in the CSV file: age,name,locationIs it possible to INSERT data into the CSV into the correct age order. For example, if I had... (1 Reply)
Discussion started by: whyte_rhyno
1 Replies

8. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

9. Shell Programming and Scripting

Script to ingest a csv, validate data and insert into Oracle

Hi all i would appreciate your help... I am looking for a set of unix commands which i can use to 1) ingest a csv file with a known format 2) validate the filename 3) validate the data/datatypes 4) Insert into an oracle db Can you help get me started? yogz888 (1 Reply)
Discussion started by: yogz888
1 Replies

10. UNIX for Beginners Questions & Answers

Possible to insert a few lines of code into a file at a specific point?

Hi Folks - How would I go about inserting a chunk of lines (3) into a specific portion of a file? The background is I have a script (non shell) that it executed daily, however on Sundays, I uncomment a section of code so that piece can be run as well. So I was hoping to write a piece of... (9 Replies)
Discussion started by: SIMMS7400
9 Replies
wnn_hinsi.data(4)						   File Formats 						 wnn_hinsi.data(4)

NAME
wnn_hinsi.data - Wnn6 part of speech administration file SYNOPSIS
/usr/lib/locale/ja/wnn/ja/hinsi.data DESCRIPTION
hinsi.data is a file that contains information required to administer the main parts of speech. Numbers are allocated in the order of the parts of speech and composite parts of speech defined in hinsi.data. These numbers are used when creating dictionary files and part of speech files, when looking up part of speech names by numbers from the client and server, and looking up the parts of speech in composite parts of speech. Numbers are assigned in ascending order starting at 0. Only the following operations are allowed for this file: appending new parts of speech or composite parts of speech to the end of the file and replacing lines consisting of only "@" with definitions of parts of speech or composite parts of speech. NEVER DELETE ENTRIES. "@" is used to reserve lines in the file in advance when part of speech names have not yet been determined. The part of speech formats for lines in this file are as follows: part_of_speech composite_part_of_speech $ part_of_speech : part_of_speech:...:part_of_speech All parts of speech appearing in definitions of composite parts of speech must be defined before the composite part of speech can be defined. There must not be more than one part of speech or composite part of speech with the same name. Everything on a line following a semicolon (;) is treated as comment and ignored. Information on this file (looking up part of speech names from part of speech numbers and looking up the structural elements of composite parts of speech) are provided by the library and can thus be referenced through the client process. EXAMPLES
Example 1: [SENTOU] ;Beginning of a sentence [MEISHI] ;Indicates a noun. [ICHIDAN] [ICHIDANMEI]$[ICHIDAN]:[MEISHI] ;A composite part of speech @ @ NOTES
Information on the main parts of speech must be consistent between all dictionaries and connection information files. Do not edit and change hinsi.data. (If the file is changed, the meaning of the part of speech numbers in dictionaries and connection information files created with the old part of speech administration file will change.) SunOS 5.10 28 May 1998 wnn_hinsi.data(4)
All times are GMT -4. The time now is 10:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy