Sponsored Content
Top Forums Shell Programming and Scripting sed help - search/copy from one file and search/paste to another Post 302548221 by Chubler_XL on Wednesday 17th of August 2011 10:13:49 PM
Old 08-17-2011
Not sure about using sed for this, but here is a solution using awk:

Code:
awk 'NR==FNR { K[$1]=$0; next }
{ if($1 in K) $0=K[$1]; print }' fileB fileA

Or if you only want to search/replace for a given value:

Code:
awk -vN=AS11000022010  'NR==FNR { if($1 == N)K[$1]=$0; next }
{ if($1 in K) $0=K[$1]; print }' fileB fileA


Last edited by Chubler_XL; 08-17-2011 at 11:19 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search and paste a line..

Hi everyone, I've never used Unix ever in my life and I just got a summer job that requires me to manipulate Unix =( I'm currently encountering a problem... I need to search for Keyword in a text file, and if I find Keyword , I'll have to output the whole line that contains Keyword into a new... (4 Replies)
Discussion started by: SeanDM
4 Replies

2. Shell Programming and Scripting

Search for strings & copy to new file

Hi All, I am just learning shell programming, I need to do the following in my shell script. Search a given log file for two\more strings. If the the two\more strings are found then write it to a outputfile else if only one of the string is found, write the found string in one output... (2 Replies)
Discussion started by: amitrajvarma
2 Replies

3. UNIX for Advanced & Expert Users

File extension search and copy

Hi need to know if we can write a shell script to find files for a particular format;s ie both .csv and .txt in a particular folder and then copy them to a new folder on a dialy basis. Does anyone know how this can be accomplished? Thanks, Sandeep (20 Replies)
Discussion started by: bsandeep_80
20 Replies

4. Shell Programming and Scripting

Search and copy to a new file-Help

Hi All, server16.na.in.com UNKNOWN ftpuser "CWD" dms-imrm/Delasco_Invoices_DayForward_Scan" 250 - server16.na.in.com UNKNOWN ftpuser "PWD" 257 - server16.na.in.com UNKNOWN ftpuser "CWD Private" 250 - server16.na.in.com UNKNOWN ftpuser "PWD" 257 - server16.na.in.com UNKNOWN... (7 Replies)
Discussion started by: Tuxidow
7 Replies

5. Shell Programming and Scripting

Search, copy and paste

Can i search in a file for more than one string at a time? And copy the next string after that and paste it in column style? Is it possible? Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

6. Shell Programming and Scripting

Search multiple strings on a file and copy the string next to it

I tried awk for this, but failed <or my code is not correct? I dont know>. Can anyone help me on this? ---------- Post updated at 08:34 PM ---------- Previous update was at 08:29 PM ---------- my working file looks like this: <empty> <empty> <empty> NAME :ABC AGE :15 GENDER... (6 Replies)
Discussion started by: kingpeejay
6 Replies

7. Shell Programming and Scripting

sed copy paste

Hello, I have this path and file: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txt I want to end up with: /dir/dir/dir/dir/dir/dir/dir/dir/dir/THIS_SPOT/fle.txtTHIS_SPOT Take the dir after the 10th slash, add a tab at the end and paste the dir it copied. Thanks (4 Replies)
Discussion started by: crowman
4 Replies

8. Shell Programming and Scripting

search a word and copy the file

Hi need help with a script or command My requirement is - I need to do a "ls -ltr tcserver*.syslog" files in /tmp, direct the output to a file ls -ltr tcserv*.syslog | grep "Jan 31" | awk '{printf "\n" $9}' > jandat.logs -Then open each file in above list and search for string/word,... (4 Replies)
Discussion started by: karghum
4 Replies

9. Shell Programming and Scripting

Search the pattern and copy in to the file

my qn is i have one file hex.txt.it contains some junk data and some hexa valueslike hex.txt sdfjhjkh 0x1233jkfhgjfhgajk;gha 0xacdd jkgahfjkgha;sjghajklgha;gh aghfjkgh;a 0xccc jhfjkhsd ox23cd 0x456 jkhdfjhjkafh like this now iwant a script like to separate the hex values and paste into the... (12 Replies)
Discussion started by: siva.hardwork
12 Replies

10. Programming

Writing a search, copy and paste program

Hello, Can some one help me by writing me the script of a program that does the following simple functions on a Linux Mint: 1. it runs in the background all the time, doing nothing except of checking if there is any external device mounted. 2. when the device is detected, it copies files... (1 Reply)
Discussion started by: Black_Ardilla
1 Replies
search.h(3HEAD) 						      Headers							   search.h(3HEAD)

NAME
search.h, search - search tables SYNOPSIS
#include <search.h> DESCRIPTION
The <search.h> header defines the ENTRY type for structure entry, which includes the following members: char *key void *data and defines ACTION and VISIT as enumeration data types through type definitions as follows: enum { FIND, ENTER } ACTION; enum { preorder, postorder, endorder, leaf } VISIT; The size_t type is defined as described in <sys/types.h>. See types.h(3HEAD). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
hsearch(3C), insque(3C), lsearch(3C), tsearch(3C), types.h(3HEAD), attributes(5), standards(5) SunOS 5.10 10 Sep 2004 search.h(3HEAD)
All times are GMT -4. The time now is 09:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy