Bash to verify each line in input for specific pattern
In the bash below the out put of a process is written to input. What I am trying to do is read each line in the input and verify/check it for specific text (there are always 6 lines for each file and the specific text for each line is in the description). There will always be 6 lines in each specific file in input, however the file number can vary. In this example there are 3 specific files (each color block is a file with 6 lines), but the next time there may only be two. If each line in the file is a match to description then the file is verified/good, but if it does not then the file is not.
I hope the below is a start and have commented each line. Thank you .
input
Description
Last edited by cmccabe; 05-17-2017 at 10:04 AM..
Reason: added description
File 1 has 6 lines in it:
Since "LINE IS GOOD" = 6 then File1 is verified (desired output), but if the pattern is anything else then the "LINE IS GOOD" will be less than 6 so the File is not verified.
File 2 has 6 lines in it:
Since "LINE IS GOOD" = 6 then File1 is verified (desired output), but if the pattern is anything else then the "LINE IS GOOD" will be less than 6 so the File is not verified.
File 3 has 6 lines in it:
Since "LINE IS GOOD" = 6 then File1 is verified (desired output), but if the pattern is anything else then the "LINE IS GOOD" will be less than 6 so the File is not verified.
desired output
It is also possible that there could only be 1 or two files, but there will always be 6 lines in each file. I use FILENAME to represent each file instead of hardcoding it in.
Still not 100% sure, could you please try following and let me know if this helps you.
You could mention in above as file* if you have only files with digits in them else you could change the regex to file[0-9] etc depending upon your files. EDIT: Adding a non-one liner for of solution too successfully now.
Thanks,
R. Singh
Last edited by RavinderSingh13; 05-17-2017 at 12:33 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
I am not sure what you mean by changing the regex, but each file is a block of 6 lines within input.
input.txt (file that has the output of the process)
individual files within input.txt (in this example there are 3, but it is possible to have only 1 or 2)
I changed the NR== to skip the header (not sure if that the best). Also would adding print FILENAME " is not verified." capture any negative results where the files did not meet the expected lines (had different values)?
Your description is rather confusing, I think the following may come closer to doing what you want:
If input.txt contains the sample input you provided in post #5 in this thread, the text produced by the above script in verify.txt exactly matches the output you said you wanted.
Hello,
I need to cut a specific pattern from a line irrespecitve of knowing field place.
I am aware to cut field if you know the place of the field, but for me The sting place varies.
1468129514436,0,something_error,Non HTTP response code: java.net.URISyntaxException,Non HTTP response... (5 Replies)
Hi
This is my first post and I'm just a beginner. So please be nice to me.
I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file?
I have tried sed -n 241,241p... (13 Replies)
Hello All
I'm trying to change one string from a file contening this patern:
xxxx-xxxx
4 numbers - end 4 other numbers
This is a sample of the file:
LDR 00679 am a2200205 4500
=001 3617
=008 030219s2000\\\\xxx|||||\||||\00|\0\spa\d
=020 \\$a0211-1942
=041 \\$aCastellà
=093 ... (5 Replies)
Hi,
I'm trying to replace a string with sed, in a text file containing this pattern:
location alpha
value x
location beta
value y
location gamma
value y
location delta
value y
location theta
value z
...
What I want to achieve is:
Find location beta into text file... (1 Reply)
Hi,
I have a file which contains 2,500,500,432 lines.
Can I know what command I should type in order just print out particular line from the input file?
eg. I just wanna to see what is the contents at line 522,484,612.
Thanks for advice. (3 Replies)
Hi,
I am getting crazy after days on looking at it:
Bash in Ubuntu 12.04.1
I want to do this:
pattern="system /path1/file1 file1"
new_pattern=" data /path2/file2 file2"
file to edit: data.db
- I need to search in the file data.db for the nth occurrence of pattern
- pattern must... (14 Replies)
Input file:
Sample1 Type pattern 842 3150
Sample1 Type range 842 3150
Sample1 Type pattern 842 1127
Sample1 Type option 842 1127
Sample1 Type length 1483 1603
Sample1 Type pattern 1483 1603
Sample1 Type length 1698 1747
Sample1 Type option 1698 1747
Sample1 Type length 1868 1935
Sample1... (13 Replies)
I need to create a script that has a user enter a value. I want to verify that the value is either 1,2, or 3. If it is not then I want them to try entering it again. I am using a while loop to force them to retry.
I am able to test the input against 1,2, and 3, but when I test agains an... (4 Replies)
Hi all,
im a linux newbie, plz help!
I have a file -
box
--------
Fox-2
--------
UF29
zip42
--------
zf-CW
SNF2_N
Heli_Z
--------
Fox
--------
Kel_1
box (3 Replies)