Find two words and join together in one file

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Find two words and join together in one file
# 1  
Old 06-02-2010
Find two words and join together in one file

Hi,

I have a huge text file like below , I need to select only lines having line Fatal joined with id.
like below i want the line to be Fatal Error for input record 25 is id = 543523. Waiting for your help.

-----Original Message-----
Acceptance with warnings for input record 24.
001 tag of record from input is
abc1123
003 tag of record from input is
ref
Record replaced based on bib control number match without a bib id match. for id = 523434 idtype = 101[warning]<DIAGNOSTIC CODE 1000016> for id = 523434 idtype = 101[warning] with additional error text

-------------------------------------------------------------
Fatal Error for input record 25.
001 tag of record from input is
145
003 tag of record from input is
abc
Record replaced based on bib control number match without a bib id match. for id = 543523 idtype = 101
-----------------------------------------------------------------
Acceptance with warnings for input record 24.
001 tag of record from input is
124
003 tag of record from input is
def
Record replaced based on bib control number match without a bib id match. for id = 523438 idtype = 101[warning
-----------------------------------------------------
Thanks a lot
# 2  
Old 06-02-2010
Code:
grep -i "Fatal"  Input.file >>  Output.file

i think ur looking for this
# 3  
Old 06-02-2010
Hi ,
Sorry i dont want that it will give only Fatal line but i want the id line also like
id =543523 which is in the seperate line

my total output should be like
Fatal Error for input record 25 is id = 543523.

Please help
# 4  
Old 06-02-2010
Try this:
Code:
awk '/^Fatal/{sub(/\.$/,"");p=$0}p&&/^Record/{print p" is id = "$17;p=""}' infile

Output:
Code:
Fatal Error for input record 25 is id = 543523

# 5  
Old 06-02-2010
scutinizer can you explain me how does awk works??

i mean i knw
Code:
/^Fatal (means from beginning of the line)

bt not sure, what is the inner query in it. i mean the command with sub

Code:
{sub(/\.$/,"");p=$0}p&&/

i also knw that $17 is the parameter for the id no.
bt hw did u deleted all the things between it,.. cudnt get tht ??

please explain if u dnt mind. thanks a lot in advance
awk '/^Fatal/{sub(/\.$/,"");p=$0}p&&/^Record/{print p" is id = "$17;p=""}' infile
# 6  
Old 06-02-2010
Hi dazdseg,

The awk command works like this: on the line that contains "Fatal" at the beginning the sub command deletes the trailing dot and the result is put in variable p.

The second part says if variable p is not empty and the start of the line contains "Record", print variable p and the text " is id = " followed by field 17. Afterwards clear the contents of variable p.

S.
# 7  
Old 06-02-2010
Hi,

Sorry,
The output is fetching me like this

Fatal Error for input record 25 is 523438(this is the id from Acceptance with warning for input record 24
but i want Fatal Error for input record 25 is 543523 of the same record.

-------------------------------------------------------------
Fatal Error for input record 25.
001 tag of record from input is
145
003 tag of record from input is
abc
Record replaced based on bib control number match without a bib id match. for id = 543523 idtype = 101
-----------------------------------------------------------------
Acceptance with warnings for input record 24
001 tag of record from input is
124
003 tag of record from input is
def
Record replaced based on bib control number match without a bib id match. for id = 523438 idtype = 101[warning

Please help

---------- Post updated at 10:46 AM ---------- Previous update was at 10:09 AM ----------

The file is exactly similar to this as written below but huge, please check and kindly guide me.
Initially the awk works fine but later on it is giving
Fatal Error for input record 27889 is id = 2394833


Fatal Error for input record 27889.
001 tag of record from input is
ocn430426837
003 tag of record from input is
OCoLC
search does not exist: for id = 2396539 idtype = 101[error] with additional error text
7 / cct

----------------------------------------------------------------------------
Acceptance with warnings for input record 27890.
001 tag of record from input is
sls2010021181
Record replaced based on bib control number match without a bib id match. for id = 2394833 idtype = 101[warning]<DIAGNOSTIC CODE 1000016> for id = 2394833 idtype = 101[warning] with additional error text
040 $c abc, 040 $d abc

----------------------------------------------------------------------------
Acceptance with warnings for input record 27891.
001 tag of record from input is
sls2010021182
Record replaced based on bib control number match without a bib id match. for id = 2394834 idtype = 101[warning]<DIAGNOSTIC CODE 1000016> for id = 2394834 idtype = 101[warning] with additional error text
040 $c abc, 040 $d abc

----------------------------------------------------------------------------
Fatal Error for input record 27892.
001 tag of record from input is
ocn489289719
003 tag of record from input is
OCoLC
search does not exist: for id = 2396540 idtype = 101[error] with additional error text
7 / cct

----------------------------------------------------------------------------
Fatal Error for input record 27893.
001 tag of record from input is
ocn600208119
003 tag of record from input is
OCoLC
search does not exist: for id = 2396541 idtype = 101[error] with additional error text
7 / cct

----------------------------------------------------------------------------
Fatal Error for input record 27894.
001 tag of record from input is
ocn600519310
003 tag of record from input is
OCoLC
Subfield data is duplicated: for id = 2396542 idtype = 101[warning] with additional error text
040 $d abc
search does not exist: for id = 2396542 idtype = 101[error] with additional error text
7 / cct

----------------------------------------------------------------------------
Fatal Error for input record 27895.
001 tag of record from input is
ocn600208128
003 tag of record from input is
OCoLC
Subfield data is duplicated: for id = 2396543 idtype = 101[warning] with additional error text
040 $d abc
search does not exist: for id = 2396543 idtype = 101[error] with additional error text
7 / cct

----------------------------------------------------------------------------
Fatal Error for input record 27896.
001 tag of record from input is
ocn489399391
003 tag of record from input is
OCoLC
search does not exist: for id = 2396544 idtype = 101[error] with additional error text
7 / cct

----------------------------------------------------------------------------
Acceptance with warnings for input record 27897.
001 tag of record from input is
ocm61030676
003 tag of record from input is
OCoLC
Record replaced based on bib control number match without a bib id match. for id = 2394841 idtype = 101[warning]<DIAGNOSTIC CODE 15751> for id = 2394841 idtype = 101[warning] with additional error text
020 $a 9787534929922
Subfield data is duplicated: for id = 2394841 idtype = 101[warning] with additional error text
040 $c SLY

----------------------------------------------------------------------------
Acceptance with warnings for input record 27898.
001 tag of record from input is
ocn428012248
003 tag of record from input is
OCoLC
Record replaced based on bib control number match without a bib id match. for id = 2394842 idtype = 101[warning]<DIAGNOSTIC CODE 1000016> for id = 2394842 idtype = 101[warning] with additional error text
040 $c CNPIT
Possible duplicate subject heading: for id = 2394842 idtype = 101[warning] with additional error text
650 $a Tales $z China.
Possible duplicate subject heading: for id = 2394842 idtype = 101[warning] with additional error text
650 $a Fishes $z China $x Folklore.

----------------------------------------------------------------------------
Acceptance with warnings for input record 27899.
001 tag of record from input is
sls2010021184
003 tag of record from input is
OCoLC
Record replaced based on bib control number match without a bib id match. for id = 2394856 idtype = 101[warning]<DIAGNOSTIC CODE 1000016> for id = 2394856 idtype = 101[warning] with additional error text
040 $c SIabc, 040 $d abc
Possible duplicate user heading: for id = 2394856 idtype = 101[warning] with additional error text
260 $b Zhongguo wen lian chu ban she,
Possible duplicate subject heading: for id = 2394856 idtype = 101[warning] with additional error text
650 $a Chinese poetry $y 20th century.

----------------------------------------------------------------------------
Acceptance with warnings for input record 27900.
001 tag of record from input is
sls2010021185
003 tag of record from input is
OCoLC
Record replaced based on bib control number match without a bib id match. for id = 2394857 idtype = 101[warning]<DIAGNOSTIC CODE 1000016> for id = 2394857 idtype = 101[warning] with additional error text
040 $c CGP
Possible duplicate user heading: for id = 2394857 idtype = 101[warning] with additional error text
260 $b Zhongguo wen lian chu ban she,
Possible duplicate subject heading: for id = 2394857 idtype = 101[warning] with additional error text
650 $a Chinese poetry $y 20th century.
Authority deleted: for id = 2394857 idtype = 101[warning] with additional error text
21130374 - Title: Dang dai shi tan bai jie jia zuo xuan / Zhu bian Huo Songlin.

----------------------------------------------------------------------------
Fatal Error for input record 27901.
001 tag of record from input is
ocn600208134
003 tag of record from input is
OCoLC
Subfield data is duplicated: for id = 2396545 idtype = 101[warning] with additional error text
040 $d abc
search does not exist: for id = 2396545 idtype = 101[error] with additional error text
7 / cct

Waiting for your reply

Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

3. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

4. UNIX for Dummies Questions & Answers

Find a file with common initials and last words

Hi, I have a requirement like i have to find out files and remove them on a daily basis. The files are generated as abc_jnfn_201404230004.csv abc_jnfo_201404230004.csv abc_jnfp_201404230004.csv abc_jnfq_201404230004.csv abd_jnfn_201404220004.csv abe_jnfn_201404220004.csv i want to... (1 Reply)
Discussion started by: Mohammed_Tabish
1 Replies

5. Shell Programming and Scripting

Find Multiple words in a file

Hi all, I have trouble in finding the multiple word in .txt file. Please help me with any solution. I have 10,000 .txt files and in each file i have to search specific word but more than one, like (data, machine learning, clustering) and all these keywords should be case insensitive because... (3 Replies)
Discussion started by: XXLMMN
3 Replies

6. Shell Programming and Scripting

Splitting concatenated words in input file with words from the same file

Dear all, I am working with names and I have a large file of names in which some words are written together (upto 4 or 5) and their corresponding single forms are also present in the word-list. An example would make this clear annamarie mariechristine johnsmith johnjoseph smith john smith... (8 Replies)
Discussion started by: gimley
8 Replies

7. Shell Programming and Scripting

Splitting Concatenated Words in Input File with Words from a Master File

Hello, I have a complex problem. I have a file in which words have been joined together: Theboy ranslowly I want to be able to correctly split the words using a lookup file in which all the words occur: the boy ran slowly slow put child ly The lookup file which is meant for look up... (21 Replies)
Discussion started by: gimley
21 Replies

8. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

9. Shell Programming and Scripting

Script to find all the files that contain any of the words present in another file

Hi All, I am new to UNIX and shell scripts and also new to this forum. I need a script to find all the files in a directory that contain any of the strings present in another file. Please provide me the script or if you could provide pointers to any link in this forum it would be helpful.... (4 Replies)
Discussion started by: tsanthosh
4 Replies

10. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies
Login or Register to Ask a Question