Cut a word between two strings and repeat the same in the entire file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Cut a word between two strings and repeat the same in the entire file
# 1  
Old 07-23-2018
Cut a word between two strings and repeat the same in the entire file

in the below data i need to search for the word typeMismatch and then traverse back to find the filename of that particular mismatch. Like this we have to get all the file names which has error in them. How can i acheive this.
I tried use sed or awk but not able to achevie the same.

Sample file.
Code:
abcdedfgh
iekigi2
kjekjijj Parsing error at line: 3 in resource=[URL [file:/home/test/TestFile_071618.txt]]
kjlkji
aio983jlk
kjalskdfj2 rejected value [testing]; codes [typeMismatch.target.processStartDtm]
abcdedfgh
iekigi2
kjekjijj Parsing error at line: 3 in resource=[URL [file:/home/test/TestFile1_071618.txt]]
kjlkji
aio983jlk
kjalskdfj2 rejected value [testing]; codes [typeMismatch.target.processStartDtm]

Need the output as:

Code:
/home/test/TestFile_071618.txt
/home/test/TestFile1_071618.txt

since there are 2 occurrence of typemismatch in the data..




Moderator's Comments:
Mod Comment Please use CODE not HTML tags.

Last edited by RudiC; 07-23-2018 at 05:48 PM..
# 2  
Old 07-23-2018
How about
Code:
awk 'match($0, /\[file:.*$/) {FN = substr ($0, RSTART+6, RLENGTH-8)} /typeMismatch/ {print FN; FN = ""}' file
/home/test/TestFile_071618.txt
/home/test/TestFile1_071618.txt

# 3  
Old 07-23-2018
or (given sample input/output):
Code:
awk -F'[]:]' 'NF>3{print $(NF-2)}' myFile
/home/test/TestFile_071618.txt
/home/test/TestFile1_071618.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. Shell Programming and Scripting

Cut the strings from end

could you please help me. I have below autosys jobs 01_enable_input_hol_dtpz1b 01_abc_copy_ld_sat_xxxz1 01_abc_mavcd_yyyyyxxxz1 01_abcdef_oa_xxxxxz1 01_fdgte_symbol_ddddz1 01_fsdfsd_clean_mmmhhhfz1 01_fsdfd_create_mut_marchtz1 I want to remove name after last "_" underscore so that... (6 Replies)
Discussion started by: sdosanjh
6 Replies

3. Shell Programming and Scripting

Repeat same word in the rest of the column.

My input is: a.txt computer b.txt c.txt e.txt I want my output to be: a.txt computer b.txt computer c.txt computer e.txt computer There are about 100000 text files having the same format as my input data. What I am doing now is too slow and also requires plenty of scripts. 1. wc -l all... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

4. Shell Programming and Scripting

Print text between 2 strings for the entire file

hey guys, for the following output: starting open open close close starting close starting open close close starting open open close open (2 Replies)
Discussion started by: boaz733
2 Replies

5. Shell Programming and Scripting

Search entire system for files containing certain word(s)

I am trying to create a script that will report (email and ftp results) on any file, system wide, that has the word password= in it. (and any variation of password=). Basicaly looking for any plain text passwds. I figured the easiest way would be like this...... for i in `cat find-pw.dat` do... (6 Replies)
Discussion started by: theninja
6 Replies

6. Shell Programming and Scripting

cut the first word in the file

how to cut the first word in multiple file at a time i.e)1st row and 1st colum word in multiple files (6 Replies)
Discussion started by: natraj005
6 Replies

7. Shell Programming and Scripting

Help need to cut the first word of a line in text file

Hi All, I would like help with a script which can get rid of the first work of all lines in text file. File 1 The name is Scott. Output : name is Scott ---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ---------- Hi ALL There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies

8. Shell Programming and Scripting

script to cut a word from the file

hi to all i wrote a script to cut a word from the file....that works only if the word is fixed field. example.. sed -n '1p'|awk '{ print $2 }'|cut -d '(' -f2|sed 's/(//'|sed 's/)//'|sed 's/"//g' filename i know that word is starting with "app" then "(" ----> ex: app("xxxx"). it... (2 Replies)
Discussion started by: honeym210
2 Replies

9. Shell Programming and Scripting

ksh :: want to cut the strings

I have contents like 423562143124/53125351276 sdgas/347236 sjhdk;ls'ald/y62783612763 I need a command that would make the string before / and after / as separate output as (A should contain 423562143124 )and B should contain 53125351276). I tried but in vain. Please help. (19 Replies)
Discussion started by: rollthecoin
19 Replies

10. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies
Login or Register to Ask a Question