Sponsored Content
Full Discussion: Adding fields to a file
Top Forums Shell Programming and Scripting Adding fields to a file Post 302745803 by Arun Mishra on Tuesday 18th of December 2012 05:30:32 AM
Old 12-18-2012
BSD Adding fields to a file

Hi All,

I have a file(Pipe Delimited) where i need to add a blank field before the last field and a blank field after the last field. Please help. I have provided below the sample input records and desired output.

Code:
Sample Input:
A0010000|Abilene TX A 1|A0010957|Dallas TX|A0010998|West|US HEADQUARTERS
A0010001|Akron OH A 1|A0010954|Cleveland OH|A0010997|Central|US HEADQUARTERS
A0010002|Alaska AK A 1|A0010991|Seattle WA|A0010998|West|US HEADQUARTERS

Sample Output Required:
A0010000|Abilene TX A 1|A0010957|Dallas TX|A0010998|West||US HEADQUARTERS|
A0010001|Akron OH A 1|A0010954|Cleveland OH|A0010997|Central||US HEADQUARTERS|
A0010002|Alaska AK A 1|A0010991|Seattle WA|A0010998|West||US HEADQUARTERS|

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding new fields to an existing layout

Hi Everybody, I have an layout file like below f1 1 char 10, f2 11 char 2, f3 13 char 1, lineend 14 char 1 Their I need to add a new field which would be like f5 char 3, f6 char 2 The o/p should be f1 1 char 10, f2 11 char 2, f3 13 char 1, f5 14 char 3, f6 17 char 2 (3 Replies)
Discussion started by: mr_manii
3 Replies

2. Shell Programming and Scripting

Adding field to file and moving the last 2 fields

I have a file with 32 fields each separated by ‘|”. I need to add a file date exactly in the format “ "20100120" “ as the 32nd field moving the existing 32nd field to 33. so the field I added should be 32nd and the 33rd field is the last field before I added the file date. I know we can... (8 Replies)
Discussion started by: dsravan
8 Replies

3. Shell Programming and Scripting

Adding new lines to a file + adding suffix to a pattern

I need some help with adding lines to file and substitute a pattern. Ok I have a file: #cat names.txt name: John Doe stationed: 1 name: Michael Sweets stationed: 41 . . . And would like to change it to: name: John Doe employed permanently stationed: 1-office (7 Replies)
Discussion started by: hemo21
7 Replies

4. Programming

regarding adding fields to DSR protocol in ns2.34

hi i am student doing project in ns2.34. i hav to add field in route cache and packet of DSR routing protocol. which files hv to be changed...pl help me (1 Reply)
Discussion started by: khubalkar
1 Replies

5. Homework & Coursework Questions

regarding adding fields to DSR protocol in ns2.34

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: want to add field to route cache and packet of DSR routing protocol in ns2.34, add field, DSR package in ns2.34... (2 Replies)
Discussion started by: khubalkar
2 Replies

6. Shell Programming and Scripting

Adding fields to file

Hi All, I have a file(Pipe Delimited) where i need to add a blank field before the last field and a blank field after the last field. Please help. I have provided below the sample input records and desired output. Code: Sample Input: A0010000|Abilene TX A 1|A0010957|Dallas... (0 Replies)
Discussion started by: Arun Mishra
0 Replies

7. Shell Programming and Scripting

Adding Fields to the file

Hi All, I get a file on weekly basis from client. I need to write a script which make sure the file should have 20 columns after the first column. If not then the script should add the remaining columns and default them to space(except for 2nd and 3rd). and at the same time the script should... (25 Replies)
Discussion started by: Arun Mishra
25 Replies

8. Shell Programming and Scripting

Awk: adding fields after matching $1

Dear AWK-experts! I did get stuck in the task of combining files after matching fields, so I'm still awkward with learning AWK. There are 2 files: one containing 3 columns with ID, coding status, and score for long noncoding RNAs: file1 (1.txt) (>5000 lines) ... (12 Replies)
Discussion started by: kben
12 Replies

9. Shell Programming and Scripting

Adding ' in particular fields

I have a file with 4 columns a|b|c|d I need to add single quotes around field 2 and 3 I need it to be like a|'b'|'c'|d (5 Replies)
Discussion started by: dsravanam
5 Replies

10. UNIX for Beginners Questions & Answers

Adding to an array in an external file, and adding elements to it.

I have an array in an external file, "array.txt", which contains: char *testarray={"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};I want to be able to add an element to this array, and have that element display, whenever I call it, without having to recompile... (29 Replies)
Discussion started by: ignatius
29 Replies
comm(1) 						      General Commands Manual							   comm(1)

NAME
comm - Compares two sorted files. SYNOPSIS
comm [-123] file1 file2 STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: command: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Suppresses output of the first column (lines in file1 only). Suppresses output of the second column (lines in file2 only). Suppresses output of the third column (lines common to file1 and file2). The command comm -123 produces no output. OPERANDS
A pathname of the first file to be compared. If file1 is a hyphen (-), the standard input is used. A pathname of the second file to be compared. If file2 is a hyphen (-), the standard input is used. If both file1 and file2 refer to standard input or to the same FIFO special, block special or character special file, the results are unde- fined. DESCRIPTION
The comm command reads file1 and file2 and writes three columns to standard output, showing which lines are common to the files and which are unique to each. The leftmost column of standard output includes lines that are in file1 only. The middle column includes lines that are in file2 only. The rightmost column includes lines that are in both file1 and file2. If you specify a hyphen (-) in place of one of the file names, comm reads standard input. Generally, file1 and file2 should be sorted according to the collating sequence specified by the LC_COLLATE environment variable. (See sort(1).) If the input files are not sorted properly, the output of comm might not be useful. EXIT STATUS
Successful completion. Error occurred. EXAMPLES
In the following examples, file1 contains the following sorted list of North American cities: Anaheim Baltimore Boston Chicago Cleveland Dallas Detroit Kansas City Milwaukee Minneapolis New York Oakland Seattle Toronto The second file, file2, contains this sorted list: Atlanta Chicago Cincinnati Houston Los Angeles Montreal New York Philadelphia Pittsburgh San Diego San Francisco St. Louis To display the lines unique to each file and common to the two files, enter: comm file1 file2 This command results in the following output: Anaheim Atlanta Baltimore Boston Chicago Cincinnati Cleveland Dal- las Detroit Houston Kansas City Los Angeles Milwaukee Minneapolis Montreal New York Oakland Philadel- phia Pittsburgh San Diego San Francisco Seattle St. Louis Toronto The leftmost column contains lines in file1 only, the middle column contains lines in file2 only, and the rightmost column contains lines common to both files. To display any one or two of the three output columns, include the appropriate flags to suppress the columns you do not want. For example, the following command displays columns 1 and 2 only: comm -3 file1 file2 Anaheim Atlanta Baltimore Boston Cincinnati Cleveland Dallas Detroit Houston Kansas City Los Angeles Milwaukee Minneapolis Montreal Oakland Philadelphia Pittsburgh San Diego San Francisco Seattle St. Louis Toronto The following command displays output from only the second column: comm -13 file1 file2 Atlanta Cincinnati Houston Los Angeles Montreal Philadelphia Pittsburgh San Diego San Francisco St. Louis The following command displays output from only the third column: comm -12 file1 file2 Chicago New York SEE ALSO
Commands: cmp(1), diff(1), sdiff(1), sort(1), uniq(1) comm(1)
All times are GMT -4. The time now is 06:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy