Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Grep if the name exists, otherwie leave blank Post 302737867 by pamu on Friday 30th of November 2012 12:34:46 AM
Old 11-30-2012
Quote:
Originally Posted by FelipeAd
Do you know how to modify your first solution if file2 has more columns?
Try

Code:
$ cat file1
name1
name2
name3
name4
name5
name6

Code:
$ cat file2
name1 group1 good
name3 group2 bad success
name4 group3 good
name6 group4 good success success
name9 group5 good
name10 group6 bad
name11 group7 good

Code:
$ awk 'NR==FNR{A[$1]=$0;next}{print A[$1]?A[$1]:$1}' file2 file1
name1 group1 good
name2
name3 group2 bad success
name4 group3 good
name5
name6 group4 good success success

I hope this helps Smilie

pamu
This User Gave Thanks to pamu For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert blank line if grep not found

Hello everyone... please help if you can -- I'm stumped. Making this work will save me hours of manual labor: I need to search file2 for pattern in file1. If pattern found append file2 line to file3. If pattern not found append a blank line to file3. file1 contents example: 123 456 789... (6 Replies)
Discussion started by: michieka
6 Replies

2. UNIX for Dummies Questions & Answers

how to grep for blank records (space,tab,/n)?

I want to exclude (-v) blank records from a file before analysing it. I know I can use '^]$' for spaces and tabs but how do you look for lines that have nothing (/n or line feed) ? (2 Replies)
Discussion started by: Browser_ice
2 Replies

3. Shell Programming and Scripting

Help me! grep the log file without blank lines in column

Hi, I have log file like this: i want grep the log file without blank lines in column 4. So the file is become like this : What is the command? please help me. (1 Reply)
Discussion started by: justbow
1 Replies

4. UNIX for Dummies Questions & Answers

Matching exact string with blank space using grep

hi! i'm trying to get grep to do an exact match for the following pattern but..it's not quite working. I'm not too sure where did I get it wrong. any input is appreciated. echo "$VAR" | grep -q '^test:]name' if ; then printf "test name is not found \n" fi on... (4 Replies)
Discussion started by: jazzaddict
4 Replies

5. Shell Programming and Scripting

Grep pattern from different file and display if it exists in the required file

Hi, I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which contains rubbish information just to fill the page which is of no use. this is... (3 Replies)
Discussion started by: abinash
3 Replies

6. Shell Programming and Scripting

Insert blank line if grep not found

Hi all, I've googling around forum regarding my prob, the nearest would same as thread tittled Insert blank line if grep not found, but she/he did not mention the solution, so I would like to request your help I've this task, to search in file2 based on pattern in file1 and output it to... (4 Replies)
Discussion started by: masterpiece
4 Replies

7. UNIX for Dummies Questions & Answers

Grep command to remove blank lines

The following grep command grep -v "^$" filename > newfilename does not populate the new file with any data. I see it search the entire input file but the output file never gets filled. Is this not the correct command for what Im looking to do? (2 Replies)
Discussion started by: aispg8
2 Replies

8. Shell Programming and Scripting

grep to remove blank space

Hi All, Need help to grep blank and copy to file. I have a file in below format dns1dm06_10, dns2dm02_04, dbidub,10000000c9a46d0c gbpuhci,10000000c948b00a ibtur001,10000000c9a1ccda yubkbtp1,10000000c93fec5b I need to copy to all lines which doesn't have wwn >> no-wwn.txt 1... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

9. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

10. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies
SHAPE_PATCH(1)						      General Commands Manual						    SHAPE_PATCH(1)

NAME
shape_patch - shapeTools RMS generate patch file SYNOPSIS
shape patch OLDRELEASE=<name1> NEWRELEASE=<name2> [PATCHFILE=<filename>] DESCRIPTION
Shape patch generates a patch file for updating $(OLDRELEASE) to $(NEWRELEASE). Both releases are identified by release names associated with the macros OLD-/NEWRELEASE on the command line. Valid release names are those generated by any of the shape_RMS (pre-)release building procedures (see shape_releas(1)). Performing 'vl -all' with the release identification file as argument usually gives a good overview of existing release names. Patch generation happens recursively over all subsystems being part of the current node. Hence, triggering shape patch from the top node of the central source repository creates a patch file for the whole system. The output of shape patch is stored in a file named <name1>+2+<name2>.pat. When the PATCHFILE macro is set on the command line, $(PATCH- FILE) is taken as output file name instead. Defining PATCHFILE=- on the command line causes the patch to be written to standard output. Note: For patches invoking multiple subsystems, $(PATCHFILE) should be set to an absolute pathname. If not, the patch generation procedure will leave an equally named patch file for each visited subsystem. The patch is constructed using the vdiff(1) command and can be applied to any installation of $(OLDRELEASE) by invoking patch(1). INCONVENIENCES
On System V machines, the generated patch file name will almost certainly exceed the 14 characters filename length limit. SEE ALSO
shape_releas(1), vdiff(1), patch(1) FILES
<name1>+2+<name2>.pat 24.8.119 SHAPE_PATCH(1)
All times are GMT -4. The time now is 07:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy