Sponsored Content
Top Forums Shell Programming and Scripting Compare entries in two files, output one of them in bash Post 302296313 by forthekill on Tuesday 10th of March 2009 10:41:10 PM
Old 03-10-2009
Compare entries in two files, output one of them in bash

I have two files which are of the following format:

File1:
Unnamed
Unnamed
Boston
Unnamed
New_York
Unnamed

File2:
San_Francisco
Chicago
Portland
Austin
Orlando
Los_Angeles

In the case where an entry in File1 is "Unnamed", I want to output the name from the same line in File2. In the case where the entry in File1 is a name, then I want to output the name from File1.

I want the output to be a file, preferably into File 2, although having the output as File3 would be OK too.

I'm new to using bash, and I can't seem to figure out how to do this. Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Compare Files and Output Difference

I have to compare two files for any differences, then output the lab and question number for any differences. This is what I currently have: diff lab2.txt lab2answer.txt > lab2compare.txt Though the output doesn't have to be sent to a .txt (or any sort of log), I found that easier, at least... (2 Replies)
Discussion started by: Joesgrrrl
2 Replies

2. Shell Programming and Scripting

Compare 2 files and send output to other

Hi, In File1.txt I have text like: 23AA3424DD23|3423ff25sd5345| and so on In File2.txt I have similar text as File1, but with ",": 23aa3424dd23,192.168.1.100, and so on I wan to remove the pipes from File1 and select 5 fields, then remove "," from File2.txt and select 2 fields (IP's... (14 Replies)
Discussion started by: cameleon
14 Replies

3. Shell Programming and Scripting

compare 2 files > output new to third

Hi, I have a question of comparing to files and output the result third file where file1 is the mainfile containing processed dir data and 2nd file grepīs dirīs data again (could be newer dirs comparing file1<file2) now i wanna make shure that output in file3 only contains newer dirs hx... (1 Reply)
Discussion started by: needle
1 Replies

4. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together. I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Discussion started by: bkeep
4 Replies

5. Shell Programming and Scripting

Compare two files and get output

Hi, I have two files, file1 and file2 and I need to compare them by line (exact match, order of the lines is not important) and get output with lines from file2 that are not found in file1 (not other way around). How do I do that? With grep or otherwise.. Thankyou (2 Replies)
Discussion started by: orp56
2 Replies

6. Shell Programming and Scripting

Compare 2 files and output only the different text.

I know the diff does this but it does output more info than just the different text (e.g. $ diff file1 file2 29a30 > /home/alex/Pictures/hello.jpg 1694a1696 > /home/alex/Pictures/hi.jpg ) How can I make it output only /home/alex/Pictures/hello.jpg /home/alex/Pictures/hi.jpg ? thank... (2 Replies)
Discussion started by: hakermania
2 Replies

7. Shell Programming and Scripting

Compare two files in different formats and get output

File A: DATAFILE TABLESPACE ------------------------- ------------------------- /dev/rprod_0032_011 D_EEM /dev/rprod_0032_012 D_ESO_REF ... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

8. UNIX for Dummies Questions & Answers

To compare two files,Output into a new file

Hi Please help me to compare two files and output into a new file file1.txt 15114933 |4001 15291649 |933502 15764675 |4316 15764678 |4316 15761974 |282501 15673104 |933505 15673577 |933505 15673098 |933505 15673096 |933505 15673092 |933505 15760705 ... (13 Replies)
Discussion started by: Ankita Talukdar
13 Replies

9. Shell Programming and Scripting

BASH - Compare 2 Files, Output All Matches

This is probably rehash but I did look. :rolleyes: I want a bash script that will take Item 1 in File1, traverse all lines in File2 and output if a match exists. Continuing the pattern recursively, Item2, File1, traverse all lines in File2 for a match, continue this pattern until all lines... (6 Replies)
Discussion started by: rcbarr2014
6 Replies

10. UNIX for Beginners Questions & Answers

Compare two files and print output

Hi All, i am trying to compare two files in Centos 6. F1: /tmp/d21 NAME="xvda" TYPE="disk" SIZE="40G" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="" NAME="xvda1" TYPE="part" SIZE="500M" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="/boot" NAME="xvda2" TYPE="part"... (2 Replies)
Discussion started by: balu1234
2 Replies
ggParseOptions(3)							GGI							 ggParseOptions(3)

NAME
ggParseOptions - Option parsing SYNOPSIS
#include <ggi/gg.h> char *ggParseOptions(const char *str, gg_option *optlist, int count, int flag); DESCRIPTION
ggParseOptions parses a string str of options in LibGG's option format and places the results in the ".name" members of the optlist. The parameter count specifies the length of optlist. The parameter flags is a bitwise or of values that alter behavior, the only one defined at this time being GG_PARSEOPTS_ALLOW_UNKNOWN, which, if present, will cause ggParseOptions to ignore options found in the string for which there are no matching entries in optlist (normally this generates a failure and a warning message). The normal LibGG option format is defined as follows: A colon or whitespace is the separator between options. Option names consist of any character except parenthesis, colons, whitespace characters, the equals sign ('=') and the NULL ('0') charac- ter. Option values may consist of any character except the NULL character, however in order to include colons, whitespace characters, or paren- thesis, the option must be quoted. Option values that begin with a single or double quote are considered to be quoted, and must end with the same quote character with which they began. The quotes are not considered to be part of the option value. In order to include the quote character in use in a quoted option value it must be escaped by a backslash ('') character. Backslashes always escape, even in unquoted values, and so must always be escaped with a backslash in order to be included. Named options begin with a dash (-) character followed by an option name and may be boolean (present or not) or may contain an equal sign to assign the option a string value (everything following the equal sign up to the next forbidden character as described above.) Matching is case sensitive, but options can be abbreviated right down to a single letter as long as the name remains unique among the entries in optlist and the GG_PARSEOPTS_ALLOW_UNKNOWN flag is not used. Unnamed options do not (duh) have a name field and are positionally mapped to entries in optlist. Unnamed options are processed after the first option field not starting with a dash is encountered, and occupy the rest of the option string. They are assigned to any unnamed- eligible options (see below) in the order they appear in optlist, but if any were previously discovered in named form they forfeit their position in that order. Options that are eligible to be used in an unnamed fashion must have a colon or dash prefixed to their optname in the optlist when ggParseOptions is invoked. Unnamed options may appear as named options as well. ggParseOptions will alter the first character in the cor- responding optname entry in optlist to a colon or to a dash depending on whether the option was present in unnamed or named form, respec- tively. Thus the caller can determine whether the option was presented in named or unnamed form. Options that appear in boolean form will have the first character in their result changed to "y". This can be distinguished from an explicit value of "y" because no NULL terminator is appended to the "y". Options that are not found are left unaltered in optlist. Option names and values in str are limited in length to GG_MAX_OPTION_NAME and GG_MAX_OPTION_RESULT bytes, respectively, including one byte for a terminating NULL character. RETURN VALUE
ggParseOptions returns the position in str after the last character of a valid option string, or NULL if str was determined not to be a valid option string. Even on failure, the contents of optlist may have been altered. libgg-1.0.x 2005-08-26 ggParseOptions(3)
All times are GMT -4. The time now is 04:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy