How do I display the filename that has been awk to each of the line in Unix, i need to so far I have tried {print FILENAME;nextfile} but to no avail.
Code:
`awk -F, '/1.2 Install TCP Wrappers/ {P=0} /1.1 Apply latest OS patches/ {P=1} P' solarisappsummary.txt solarisdbsummary.txt`
Code:
For solarisappsummary.txt
1.1 Apply latest OS patches
Oracle Solaris 10 8/11 s10x_u10wos_17b X86
For solarisdbsummary.txt
1.1 Apply latest OS patches
Oracle Solaris 10 8/11 s10x_u10wos_17b X86
You can try following changes in your code and let me know if that helps.
1st: Please change . to \., to remove it's special meaning in search part of awk. For example into your case. /1\.2 Install TCP Wrappers/ AND /1\.1 Apply latest OS patches/.
2nd: As mentioned by you in your post, on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk, or nawk.
3rd: Also I have seen symbol ` in starting of awk if you are NOT storing this result to a variable then kindly remove them too.
Your description isn't at all clear. Why are you setting the input field separator to a comma if you aren't doing anything with any fields? If you're trying to print a line giving the name of the file followed by the contents of the file, try:
If you're trying to print files with the file's name at the start of each line from that file, try:
Code:
awk '{print FILENAME, $0}' file1 file2
If you're trying either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
If neither of these are what you're trying to do, show us some sample contents for your two input files, give a full English description of the changes you want to make to the input, and show us the output you're trying to produce from those sample inputs.
The two code segments you have shown us do not even come close to doing what you described. And, the various versions of awk on most Solaris systems do not include a nextfile operator (and your description doesn't seem to need it even if your version of awk does include it).
Your description isn't at all clear. Why are you setting the input field separator to a comma if you aren't doing anything with any fields? If you're trying to print a line giving the name of the file followed by the contents of the file, try:
If you're trying to print files with the file's name at the start of each line from that file, try:
Code:
awk '{print FILENAME, $0}' file1 file2
If you're trying either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
If neither of these are what you're trying to do, show us some sample contents for your two input files, give a full English description of the changes you want to make to the input, and show us the output you're trying to produce from those sample inputs.
The two code segments you have shown us do not even come close to doing what you described. And, the various versions of awk on most Solaris systems do not include a nextfile operator (and your description doesn't seem to need it even if your version of awk does include it).
Hi,
Managed to solved my problem already thanks.
Code:
$ echo "1.1.1.3.1.1.1;"`var=$(awk '/Privilege Use/ {P=0} /Object Access/ {P=1} P {print FILENAME, $0}' AdvancedAudit.txt AdvancedAudit2.txt | grep -ia 'File System') ; echo $var; echo $var | grep -iq "No Auditing" && echo ';T' || echo ';F' `
1.1.1.3.1.1.1;AdvancedAudit.txt File System No Auditing AdvancedAudit2.txt File System No Auditing ;T
<tr><td>4.4.1.2 </td><td>
File Regedit_NTSLA56.txt:
File Regedit_NTSLA57.txt:
File System32_NTSLA56.txt:
NT AUTHORITY\SYSTEM:F <br>
<br>
File System32_NTSLA57.txt:
NT AUTHORITY\SYSTEM:F <br>
<br>
File SystemDrivePermission_NTSLA56.txt:
File SystemDrivePermission_NTSLA57.txt:
NT AUTHORITY\SYSTEM:F <br>
<br>
Code:
C:\WINDOWS\system32\regedt32.exe BUILTIN\Administrators:F
NT AUTHORITY\SYSTEM:F
C:\WINDOWS\system32\dllcache\regedt32.exe BUILTIN\Administrators:F
NT AUTHORITY\SYSTEM:F
I have a log file which contains information like below (more than 200 ERROR sets).
Here I want to find first .c file and function after "ERROR: AddressSanitizer" line.
If you see here after "ERROR:" line first
file - asfrecohandling.c
function - ASFPotRecoHandling_Create_RecPaxSrvcComp
... (6 Replies)
Please can you let me know how to print all the matching lines from a file in one single line using awk. Thanks
I have the following data in the input file
data1
voice2
voice1
speech1
data2
data3
...
...
voice4
speech2
data4
and the output should be as follows
data1 data2... (4 Replies)
awk 'BEGIN{IGNORECASE=1} /error|warning|exception/ { ++x } END { print x }' filename
The above command returning the number of times the pattern present in the file. But I want the the line number as well. please help me out (6 Replies)
Hello,
i want to use new line character in cut command
i want to display 3rd line of a file using cut only( not by sed or head -tail command)
can anyone suggest me ?
Regards (12 Replies)
Hi. Is there a way in awk to show all lines between a line number and the next line containing a particular regex? We can do these, of course:
awk '/regex1/,/regex2/' filename
awk 'FNR > X && FNR < Y' filename
But can they be combined? Thanks. (3 Replies)
Hello,
I cannot figure this one out. I would like to do the following. I have a line that has 7 words. It is possible that the line can have 20 words too. I always want to show the 9th word and beyond. The 9th word will always change so I do not have something to search for, so I think... (1 Reply)