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
sccsfile(5)							File Formats Manual						       sccsfile(5)

Name
       sccsfile - format of SCCS file

Description
       An  SCCS  file  is  an  ASCII file that consists of six logical parts.  These six parts include checksum, delta table (contains information
       about each delta), user names (contains login names and/or numerical group IDs of users who may add deltas), flags (contains definitions of
       internal  keywords),  comments (contains arbitrary descriptive information about the file), and body (contains the actual text lines inter-
       mixed with control lines).

       Throughout an SCCS file there are lines that begin with the ASCII SOH (start of heading) character (octal 001).	This  character  is  here-
       after  referred	to as the control character and will be represented graphically as @.  Any line described that is not shown beginning with
       the control character is prevented from beginning with the control character.

       Entries of the form represent a 5-digit string number between 00000 and 99999.

       The logical parts of an SCCS file, described in detail, are:

       Checksum
	      The checksum is the first line of an SCCS file.  The form of the line is:
	      @hDDDDD

	      The value of the checksum is the sum of all characters, except those of the first line.  The provides a magic  number    of  (octal)
	      064001.

       Delta table
	      The delta table consists of a variable number of entries of the form:
	      @s DDDDD/DDDDD/DDDDD
	      @d <type> <SCCS ID> yr/mo/da hr:mi:se <pgmr> DDDDD DDDDD
	      @i DDDDD ...
	      @x DDDDD ...
	      @g DDDDD ...
	      @m <MR number>
		.
		.
		.
	      @c <comment> ...
		.
		.
		.
	      @e

       The first line contains the number of lines inserted/deleted/unchanged, respectively.  The second line contains the type of the delta (nor-
       mal: and removed: the SCCS ID of the delta, the date and time of creation of the delta, the login name corresponding to the real user ID at
       the time the delta was created, and the serial numbers of the delta and its predecessor, respectively.

       The  and  lines	contain  the serial numbers of deltas included, excluded, and ignored, respectively.  These lines are optional.  The lines
       (optional) each contain one number associated with the delta.  The lines contain comments associated with the delta.

       The line ends the delta table entry.

       User names
	      The list of login names and numerical group ID of users who may add deltas to the file, separated by newlines.  The lines containing
	      these login names and numerical group ID are surrounded by the bracketing lines and An empty list allows anyone to make a delta.

       Flags
	      Keywords used internally.  See for more information on their use.  Each flag line takes the form:

	      @f <flag> <optional text>

	      The following flags are defined:
	      @f t <type of program>
	      @f v <program name>
	      @f i
	      @f b
	      @f m <module name>
	      @f f <floor>
	      @f c <ceiling>
	      @f d <default-sid>
	      @f n
	      @f j
	      @f l <lock-releases>
	      @f q <user defined>
	      @f z <reserved for use in interfaces>

       The flag defines the replacement for the identification keyword.

       The  flag controls prompting for numbers, in addition to comments.  If the optional text is present, it defines an number-validity checking
       program.

       The flag controls the warning/error aspect of the ``No id keywords'' message.  When the flag is not present, this message is only  a  warn-
       ing; when the flag is present, this message will cause a fatal error (the file will not be retrieved or the delta will not be made).

       When the flag is present, the option can be specified with the command to cause a branch in the delta tree.

       The flag defines the first choice for the replacement text of the identification keyword.

       The flag defines the ``floor'' release: the release below which no deltas may be added.

       The flag defines the ``ceiling'' release: the release above which no deltas may be added.

       The flag defines the default SID to be used when none is specified on a command.

       The flag causes delta to insert a null delta (a delta that applies no changes) in those releases that are skipped when a delta is made in a
       new release. For example, when delta 5.1 is made after delta 2.7, releases 3 and 4 are skipped.	The absence of	the  flag  causes  skipped
       releases to be completely empty.

       The flag causes to allow concurrent edits of the same base I.

       The flag defines a list of releases that are locked against editing with the option.

       The flag defines the replacement for the identification keyword.

       The flag is used in certain specialized interface programs.

       Comments
	      Arbitrary text surrounded by the bracketing lines and The comments section typically contains a description of the file's purpose.

       Body
	      The body consists of text lines and control lines.  Text lines do not begin with the control character; control lines do.  There are
	      three kinds of control lines: insert, delete, and end, represented by the following:
	      @I DDDDD
	      @D DDDDD
	      @E DDDDD

       The digit string is the serial number corresponding to the delta for the control line.

See Also
       (1), delta(1), get(1), prs(1), sccs(1)
       An Introduction to the Source Code Control System,
       Eric Allman, Supplementary Documentation, Vol. II.

																       sccsfile(5)
All times are GMT -4. The time now is 09:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy